仅取0-10的数字,并在q上终止

时间:2017-02-18 16:08:34

标签: assembly x86

        .MODEL medium
        .STACK          ; Stack default size 1024 bytes
        .DATA           ; Data segment (for variables)

        .CODE           ; Run-able code goes in code segment
        .STARTUP        ; Handover code from OS call to typer.exe

nextc:  mov ah,8        ; Call int21 with ah=8 returns with
        int 021h        ; al equal to the ASCII character pressed
        mov dl,al       ; dl is assigned value in al, dl=al

        mov ah,02h      ; Call int21 with ah=2 prints ASCII
        int 021h


        cmp dl,'q'      ; compare dl with ASCII ‘q’=
        jz qt           ; if key pressed was not a ‘q’ go back

        cmp dl,'/'
        jnc skp 

        cmp dl,'9'      ;;compair 9 to q. if there is a carry 9<q  
        jc skp
skp:        
        jmp nextc

qt:
        .EXIT           ; Terminate and return control to OS
        END             ; End of file (for compiler) 

1 个答案:

答案 0 :(得分:0)

只需使用jl(小于的时候跳转)和jg(大于的时候跳转)指令。

cmp dl,'0'     ;compare to 0
jl skp         ; if less then skip

cmp dl,'9'     ;compare to 9
jg skp         ;if greater than skip

success:       ;yes we;ve found a digit.
.....
skp:           ;no digit.          
.....

此处列出了所有可用的条件跳转:http://x86.renejeschke.de/html/file_module_x86_id_146.html