Vyan
Vyan

Reputation: 31

how to end process the program using a key in assemble language

Lowercase to uppercase vice versa. Characters. When press "X" the process will end. Here's my code:

.model small
.stack
.data
msg db 'Enter a character ',10,'$'
.code

start: 


mov ax,@data
mov ds,ax
mov ah,9
mov dx,offset msg
int 21h
mov ah,1
int 21h


Y:
cmp al,'a'
jb X
cmp al,'z'
ja unchanged
sub al,20h
jmp unchanged


X:
cmp al,'A'
jb unchanged
cmp al,'Z'
ja unchanged
add al,20h
unchanged:
mov ah,2


mov dl,al
int 21h



jmp start
mov cx,10


exit:

mov ah,4ch
int 21h


end start

Upvotes: 3

Views: 259

Answers (1)

Sep Roland
Sep Roland

Reputation: 39166

To exit on a capital X test for it at the X: label.
You don't need the mov cx,10. It will never get executed.

X:
cmp al,'X'
je Exit
cmp al,'A'

To also exit on a lowercase x add similar code at the Y: label.

Y:
cmp al,'x'
je Exit
cmp al,'a'

Upvotes: 2

Related Questions