2017-02-18 38 views
0
 .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) 
+0

我相當肯定我的邏輯是確定的,而這個問題是在臨印刷statment地方 – Aaron

+0

對不起窮人的解釋,但即時通訊試圖讓它打印包含0-9的數字並在q上終止。 – Aaron

+0

我在我的手機,但你的嘗試是在某種程度上在正確的方向。你需要檢查輸入的內容。但是你沒有檢查0-9的所有內容。 –

回答

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

+0

對於8位ASCII碼,我寧願使用'ja' /'jb'(無符號比較)。測試字節值爲簽名的Java級別的奇怪。 (儘管在這種特殊情況下它可以正常工作) – Ped7g