Reputation: 1
The program I am writing should read in user input from the keyboard. Instructions: If the character is an upper case letter (A-Z), blank (space) or period, then write it to the standard output. If its lowercase then convert it to uppercase and write to standard output. If the character is anything else just throw the character away. After processing the character, if the character is a period (2Eh) then end your program’s execution.
My code works until I enter a period at which point it prints the period, and then the cursor moves over one spot and blinks indefinitely.
.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 ;
Upvotes: 0
Views: 1587
Reputation: 79982
Processing simply continues into whatever is in memory after exit_
has shown the dot.
To terminate the program, you need to explicitly execute a terminate program function. There's more than one, but
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
The value in AL
when INT 21H/4ACH
is executed appears as the ERRORLEVEL in batch... I've not set it, so it'll be whatever is in AL
at the time...
Upvotes: 1