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
相关推荐
ThornArmor7 天前
【工具篇·番外】跨语言生态的主权回收:基于 ISA 说明书的 4-bit 双向汇编系统全线封顶
c语言·开发语言·汇编·c++·重构·架构
是星辰吖~7 天前
WIN32_线程(下)
汇编
是星辰吖~8 天前
WIN32_线程(上)
汇编
AI科技星8 天前
数术工坊 · 第四卷 橡皮泥江湖(拓扑学)【完整定稿】
c语言·开发语言·汇编·electron·概率论·拓扑学
iCxhust9 天前
C# 生成命令行程序 将hex格式烧录程序转换成bin烧录格式
开发语言·汇编·单片机·嵌入式硬件·c#·微机原理
iCxhust9 天前
C#进程管理程序
开发语言·汇编·stm32·单片机·c#·微机原理
hhcgchpspk9 天前
汇编语言传递数据和地址的误区
汇编·笔记·nasm·masm
iCxhust9 天前
MTK8088单板机制作(一)时钟电路
汇编·单片机·嵌入式硬件·微机原理·8088单板机
iCxhust10 天前
8086 汇编位测试使用方法
汇编·单片机·嵌入式硬件·微机原理·8088单板机
iCxhust10 天前
用汇编在8088单板机上创建一个进程
汇编·微机原理