dosgetch.asm

来自「国外网站上的一些精典的C程序」· 汇编 代码 · 共 70 行

ASM
70
字号
        page    55, 132;  FUNCTIONS: dosgetch/doswaitch;;  Donated to the public domain 96-11-12 by Tom Torfs (2:292/516);;  dosgetch() attempts to read a character from stdin. Returns the;  character read or EOF (-1) if no character is available. Extended keys;  are returned in two parts: first a zero and then the actual code.;;  doswaitch() works alike but waits if no character is available.;;  Requires MASM 5.1 or later or equivalent;;  Assemble with:       MASM /Mx /z ...;                       TASM /jMASM /mx /z ...;%       .MODEL  memodel,C               ;Add model support via                                        ;command line macros, e.g.                                        ;MASM /Dmemodel=LARGE        .CODE;; int dosgetch(void) - comments see above;        PUBLIC  dosgetchdosgetch        PROC        push dx        mov     ah, 6                   ; direct console I/O        mov     dl, 255                 ; read a character        int     21h                     ; let DOS do the job        pop dx        jz      nochar                  ; character ready ?        xor     ah,ah                   ; clear high byte ax        ret                             ; returnnochar:        mov     ax, -1                  ; return EOF        ret                             ; returndosgetch        ENDP    ;; int doswaitch(void) - comments see above;        PUBLIC  doswaitchdoswaitch       PROCwaitloop:        call    dosgetch               ; try to read character                cmp     ax, -1                 ; available ?        je waitloop                    ; no -> repeat        ret                            ; returndoswaitch       ENDP            end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?