I have an assignment that is described like so:
- Reads printable characters (20h-7Fh) from the keyboard without echoing
- Uppercase letters are printed to display
- Lowercase letters are converted to uppercase and then printed to display
- Blank spaces and periods are printed to display; everything else is trashed
- Program ends when period is printed
My program so far is this:
.model small
.8086
.data
.code
start:
mov ax,@data
mov ds,ax
read:
mov ah,8
int 21h
cmp al,61
jl write
cmp al,7fh
jg read
sub al,20h
jmp write
write: cmp al,20h
jl read
mov dl,al
mov ah,2
int 21h
cmp dl,2eh
jne read
exit:
mov ax,4c00h
int 21h
end start
My program succesfully converts lowercase letters and prints the corresponding uppercase letter, but I am having trouble trashing everything else. What is the best way to only allow blank spaces, periods, and letters through to the display?
Looking at the ASCII chart,
21h - 2Dh can be trashed
2Fh - 40h can be trashed
5bh - 60h can be trashed
7bh - 7fh can be trashed
Can anyone help me come up with the best logic for comparing the input to these values and then trashing those that fall between the range above? We are graded on efficiency, with 0-20 instructions written awarded full credit. I am already at 20 instructions here and I haven’t included compares to find the trash values.
EDIT
Here is what I have narrowed my code down to:
.model small
.8086
.data
.code
read:
mov ah,8
int 21h
cmp al,' '
je write
cmp al,'.'
je write
cmp al,'a'
jl read
cmp al,'Z'
jg convert
convert:
cmp al,'a'
jl read
sub al,20h
write:
mov dl,al
mov ah,2
int 21h
cmp dl,'.'
jne read
exit:
mov ax, 4c00h
int 21h
end read
Currently at 21 instructions! Is there any redundancy in my code that can be removed to get it down to 20?
You might modify your logic to do something like:
writereadNote that the “fold lowercase to uppercase” doesn’t need to check to see whether the input was a letter first. Just
and xxwherexxis an appropriate value should do it (I’ll let you work out the value). This step will also modify characters other than letters, but since the next step is to check for a letter it doesn’t matter.