How can I print all the alphabet characters (A to Z, a to z)?
I did the following. It lets me print all the characters from A-Z and a-z but the problem is that I get the in-between ASCII characters that I want to filter.
CX is expected to be set to 52 in a working program.
ORG 100h
MOV AX,0B800H
MOV DS,AX
MOV BX,0000 ;SET BX REGISTER
MOV CX, 58 ;USED AS A COUNTER
MOV AL,'A'
MOV AH,0x0E
MOV DL, 41h
CMP AX, DX
JG UPPERCASE
UPPERCASE:
ADD DL, 1
CMP DX, 5Bh
JG LOWERCASE
JMP BACK
LOWERCASE:
ADD DL, 1
CMP DX, 60h
JG BACK
JL UPPERCASE
HLT
BACK:
MOV [BX],AX
ADD AL,1
ADD AH,1
ADD BX,2
LOOP UPPERCASE
That's because your logic that tries to skip the range from [91,96] increments the parallel counter DL but forgets to also increment the ASCII code in AL. Of course you do not need that DL counter since AL can serve that purpose already!
You only ever initialize DL (
MOV DL, 41h), so comparing to DX is like playing Russian roulette. DH is not necessarily zeroed.This construct is non-sense in assembly programming. If the condition is greater then you jump to UPPERCASE, but if the condition is not greater then you fall-through in UPPERCASE. No matter, you will always run the code at UPPERCASE. In this program that is what you want to happen, but not in that manner.
Using 2 loops
Using 1 loop