asm汇编源代码之按键处理相关函数

提供5个子程序:

  1. 发送按键 sendkey

  2. 检测是否有按键 testkey

  3. 读取按键 getkey

  4. 判断键盘缓冲区是否为空 bufempty

  5. 判断键盘缓冲区是否已满 buffull

具体功能及参数描述如下

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| sendkey proc  far ; ax=charcode testkey proc  far ; out: ;   zf=1 buff empty; ;   zf=0 ax=key code getkey proc  far ; out: ;   ax=key code ; if buf empty, it will wait bufempty proc  far  ; test key buffer be empty or not ; out: ;   zf=0 not empty;  zf=1 empty buffull proc  far  ; test key buffer be full or not ; out: ;   zf=0 not full;  zf=1 full   |

复制代码
; more source code at http://www.ahjoe.com/source/srcdown.asp

.286
        public  sendkey, getkey, testkey, buffull, bufempty
code    segment
        assume  cs:code, ds:code

sendkey proc    far
;  ax=charcode
        push    ax
        push    bx
        push    si
        push    di
        push    ds
        cmp     ah, 0
        jnz     sendkj0
        mov     ah, 30h
sendkj0:
        mov     bx, 40h
        mov     ds, bx
        mov     di, ds:[1ch]

        mov     bx, di
        call    incptr
        cmp     bx, ds:[1ah]
        jz      fullk

        mov     ds:[di], ax
        mov     ds:[1ch], bx
fullk:
        pop     ds
        pop     di
        pop     si
        pop     bx
        pop     ax
        retf
sendkey endp                              

getkey  proc    far
; out:
;     ax=key code
; if buf empty, it will wait

        push    bx
        push    si
        push    ds

        mov     ax, 40h
        mov     ds, ax
getkeyrep:
        mov     si, ds:[1ah]
        cmp     si, ds:[1ch]
        jz      getkeyrep
        mov     ax, [si]
        mov     bx, si
        call    incptr
        mov     ds:[1ah], bx
        pop     ds
        pop     si
        pop     bx
        retf	
getkey  endp

testkey proc    far
; out:
;      zf=1  buff empty;
;      zf=0  ax=key code
        push    si
        push    ds

        mov     ax, 40h
        mov     ds, ax
        mov     si, ds:[1ah]
        mov     ax, [si]
        cmp     si, ds:[1ch]

        pop     ds
        pop     si
        retf    
testkey endp


bufempty proc    far    ; test key buffer be empty or not
; out:
;      zf=0  not empty;   zf=1  empty
        push    si
        push    ds

        mov     si, 40h
        mov     ds, si
        mov     si, ds:[1ah]
        cmp     si, ds:[1ch]

        pop     ds
        pop     si
        retf
bufempty endp

buffull  proc    far    ; test key buffer be full or not
; out:
;      zf=0  not full;    zf=1  full
        push    ds
        push    bx
        mov     bx, 40h
        mov     ds, bx
        mov     bx, ds:[1ch]
        call    incptr
        cmp     bx, ds:[1ah]
        pop     bx
        pop     ds
        retf
buffull  endp

incptr  proc    near
        inc     bx
        inc     bx
        cmp     bx, 3eh
        jb      incok
        mov     bx, 1eh
incok:
        retn
incptr  endp

decptr  proc    near
        dec     bx
        dec     bx
        cmp     bx, 1ch
        ja      decok
        mov     bx, 3ch
decok:
        retn
decptr  endp

code    ends
        end     sendkey
相关推荐
wechatbot8884 天前
企业微信API开发:登录-联系人查询-消息发送完整开发流程分享
汇编·微信·自动化·企业微信·ai编程·rpa
00后程序员张5 天前
iOS加固技术路线全面解析:Bitcode模式、源码模式与汇编模式对比及爱加密优势
android·汇编·ios·小程序·uni-app·cocoa·iphone
wechatbot8888 天前
解决企业微信官方 API 短板:iPad 协议全功能对接方案
java·汇编·windows·http·微信·企业微信
学逆向的10 天前
汇编——JCC指令
开发语言·汇编·网络安全
一只旭宝11 天前
【汇编入门】寄存器、MOV/LEA、JMP/CALL/RET、内存与指令本质
汇编
学逆向的13 天前
汇编——寻址方式
开发语言·汇编·网络安全
我不是QI13 天前
Master PDF Editor 逆向复现
汇编·安全·pdf
学逆向的13 天前
汇编——堆栈平衡
开发语言·汇编·网络安全
执迷不悟82318 天前
ARM--汇编指令
汇编·arm开发
Dlrb121120 天前
ARM指令集---汇编指令集的学习与应用:C程序与汇编的相互调用,处理器工作模式的改变等
汇编·arm开发·arm··arm指令集·汇编指令