我正在编写的程序应该从键盘读取用户输入。说明:如果字符是大写字母(AZ)、空白(空格)或句点,则将其写入标准输出。如果是小写,则将其转换为大写并写入标准输出。如果角色是别的东西,就把角色扔掉。处理完字符后,如果字符是句点(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 ;