1-Write programs to test that a character read from the keyboard and transfer control to label ok_here, if the character is:
(i) a valid lowercase letter ( 'a' <= character <= 'z' )
(ii) either an uppercase or lowercase letter ('A' <= character <= 'Z' OR 'a' <= character <= 'z')
(iii) is not a lowercase letter, ie character < 'a' or character > 'z'. The programs should display appropriate messages to prompt for input and indicate whether the character satisfied the relevant test.
i)
.Model small
.stack 100h
.code
Main proc
Mov ah,1h
Int 21h
Cmp AL,'a'
JE then
Tmp else
Then:ok_here
JMP End if
Else mov AH,4CH
Int 21h
End if
ii)
mov AH,1h
int 21h
cmp Al,'a'
JE then
Cmp AL,'A'
JE then
Cmp AL,'z'
JE then
JMP else
Then ok_here
Jmp End if
Else mov AH,4CH
Int 21h
End if
2-Write a program that reads an uppercase letter, converts it to lowercase and displays the lowercase equivalent. the program let the user repeat this process as often as desired. The user is asked to enter 'y' to carry out the operation, after each iteration.
.model small
.stack 100h
.data
CR EQU 0DH
LF EQU 0AH
MSG1 DB 'enter an uppercase letter'
MSG2 DB CRLF ' the lowercase equivalent'
CHAR DB ?
.code
Main proc
Mov AX @data
Mov DS,AX
LEA DX,MSG1
Mov AH,@H
Int 21h
SAR AL.20h
Mov CHAR,AL
LGA DX ,MSG2
Mov AH,02H
Int 21h
Mov AH,4CH
Int 21h
Main Endp
End main
Is my code correct?
No.
Your first program only tests whether AL is lowercase 'a' or not. It has also a syntax error, because you are using ok_here as an instruction, not a label (the label would be Then
). Besides, I guess that the Tmp instruction is actually the JMP instruction.
For your first program to be correct, you must test if the value in AL is equal or greater than 'a' AND is equal or less than 'z':
CMP AL,'a'
JB notok
CMP AL,'z'
JA notok
ok_here: ;if we reach this point, AL is a lowercase letter
Your second program does a similar thing: only goes to ok_here if AL is 'A', 'a' or 'z'. You only use the JE instruction, which jumps if AL is equal to the second operand of the CMP instruction. To fix it, use the previous code to test if AL is lowercase, and if it is so, repeat the test but this time with 'A' and 'Z'. That is: four CMP's and four conditional jumps.
Also, your program lacks the strings to tell the user to input a character and the printed messages telling if the character meets the criteria or not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.