Well, say I have a program that only accepts letters, regardless of its case (uppercase or lowercase), converts and displays its opposite case (eg. A to a, a to A). The program then displays the next letters through ascending and descending order BUT ONLY WITHIN THE ALPHABET.
For example, if i input 'l' and choose ascending order, it will output its corresponding uppercase equivalent as well as the next letters after it only until Z.
Input: l
Display
[a]ascending
[d]descending
Choice:a
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
likewise if I input E and choose descending order, it will output its corresponding lowercase equivalent as well as the next letters before it only until a.
Input:E
Display
[a]ascending
[d]descending
Choice:d
e
d
c
b
a
Here is a snippet of code I have accomplished so far, I have managed to convert the input letters to its uppercase and lowercase equivalents and was also able to display them vertically. My only problem is how to limit the output only to the alphabet.
startOver:
call cls
mov ah,9
lea dx,string8 ;Display the string "Input:"
int 21h
mov ah,1 ;input starting letter
int 21h
mov bl,al
call nlcr ;nlcr is a procedure for new line and carriage return
mov ah,9
lea dx,string9 ;Display the string "Display"
int 21h
call nlcr
mov ah,9
lea dx,string10 ;Display the string "[a]ascending"
int 21h
call nlcr
mov ah,9
lea dx,string11 ;Display the string "[d]descending"
int 21h
call nlcr ;nlcr is a procedure for newline and carriage return
mov ah,9 ;Display the string "Choice:"
lea dx,string12
int 21h
mov ah,1 ;input display choice if it's ascending or descending
int 21h
mov cl,al
call nlcr
cmp cl,'a' ;validate the display choice
je ascending
cmp cl,'d'
je descending
checkd:
cmp cl,'d'
je descending
cmp cl,'d'
mov ah,9
lea dx,string14
int 21h
jne startOver
ascending: ;display in ascending order
xor bl,20h ;converts letter to uppercase or lowercase
mov ah,2
mov dl,bl
int 21h
mov cx,15 ;display the letters vertically, I put a default of 15 for I am not sure how to limit it to the alphabet only
asc:
mov bl,dl
call nlcr
mov dl,bl
inc dl
int 21h
loop asc
jmp exit
descending: ;display in descending order
xor bl,20h ;converts letter to uppercase or lowercase
mov ah,2
mov dl,bl
int 21h
mov cx,15
desc:
mov bl,dl
call nlcr
mov dl,bl
dec dl
int 21h
loop desc
jmp exit
exit:
;call cls
mov ah,4ch
int 21h
main endp
Thanks for the replies!
I'd change it to something like this:
asc:
mov bl,dl
call nlcr
mov dl,bl
inc dl
int 21h
and bl,0DFh ; make sure bl is upper case
cmp bl,'Z'
jb asc ; loop until the next character would be 'z'+1 or 'Z'+1
jmp exit
And similarily for descending order; execpt then you'd compare against 'A'
and use ja
instead of jb
.