2013-09-26 46 views
0

我正在編寫的程序應該從鍵盤的用戶輸入中讀取。說明: 如果字符是大寫字母(A-Z),空格(空格)或句點,則將其寫入標準輸出。如果其小寫字母將其轉換爲大寫字母並寫入標準輸出。 如果角色是其他任何東西只是丟棄角色。 處理完角色後,如果角色是句號(2Eh),則結束程序的執行。當用戶鍵入句點時結束彙編程序

我的代碼一直工作,直到我輸入一段時間打印句點,然後光標移到一個點上並無限期地閃爍。

.model small ;64k code and 64k data 
.8086 ;only allow 8086 instructions 

.stack 256      ; 
           ; 
.data       ; 
           ; 
.code       ; 
start:       ; 
    get_l:      ; 
      mov ah, 8   ; set ah=8 to request a char  w/o echo 
      int 21h    ; [char] read is now in the al reg. 
      mov dl, al   ; save the input in dl 
    ;---------------------------------------------------------------- 
    ; test for period, if [char] is period the character prints 
    ;---------------------------------------------------------------- 
      cmp dl, 2Eh   ; is [char] a period? 2Eh to 20h 
      je exit_   ; if so, jump to exit 
    ;---------------------------------------------------------------- 
    ; if input >= a(61h) && input <= z(7Ah) then subtract 20h 
    ;---------------------------------------------------------------- 
     if_:     ; 
      cmp dl, 61h   ; compare input to a 
      jb else_if   ; if [char]<a, jump to else_if 
      cmp dl, 7Ah   ; compare input to z 
      ja else_if   ; if [char]>z, jump to else_if 
     then_1:     ; 
      sub dl, 20h   ; capitalize [char] by subtracting 20h 
      jmp print_   ; print_ [char] to console 
    ;---------------------------------------------------------------- 
    ; if input >= A(41h) && input <= Z(5Ah) then print 
    ;---------------------------------------------------------------- 
     else_if:    ; 
      cmp dl, 41h   ; compare [char] to A 
      jb else_   ; if [char]<A, jump to else_ 
      cmp dl, 5Ah   ; compare [char] to Z 
      ja else_   ; if [char]>Z, jump to else_ 
     then_2:     ; 
      jmp print_   ; print_ [char] to console 
    ;---------------------------------------------------------------- 
    ; if input == *space*(20h) then print 
    ;---------------------------------------------------------------- 
     else_:     ; 
      cmp dl, 20h   ; compare [char] to ' ' 
      je print_   ; print if space 
      jne get_l   ; ignore and repeat loop if not space 
     endif_:     ; 
    ;---------------------------------------------------------------- 
    ; print subroutine 
    ;---------------------------------------------------------------- 
     print_:     ; 
      mov ah, 2   ; set ah=2 to req. [char] to be writ 
      int 21h    ; call DOS and [char] is written 
      jmp get_l   ; go back to start of loop 
     exit_:     ; 
      mov ah, 2   ; if so, print and jump to exit_ 
      int 21h    ; 
      end start   ; 
+0

您似乎不會退出程序的'exit_:'標籤。您打印期間,然後「結束」。 –

回答

1

處理只是在exit_已顯示點後繼續進入內存中的任何內容。

要終止程序,需要明確執行終止程序功能。有不止一個,但

exit_:     ; 
     mov ah, 2   ; if so, print and jump to exit_ 
     int 21h    ; 
     mov ah,4CH   ; Terminate program 
     int 21h    ; Execute 
     end start   ; end -of-module with enntrypoint start 

當執行INT 21H/4ACHAL值顯示爲一批ERRORLEVEL ......我沒有設置它,所以它會無論是在AL的時間。 ..