Program that reads a character from keyboard and determines whether the character is a vowel or consonant.
UNIVERSITY OF THE PUNJAB
Third Semester 2015
Examination: B.S. 4 Years Programme
Paper: Computer Organization and Assembly Language
Course Code: IT-203 / 21402
Question # 3:
Write an assembly language program that reads a character from keyboard and determines whether the character is a vowel or consonant. Your program should display proper message.
Solution:
INCLUDE Irvine32.inc
.data
msg BYTE "Enter an alphabet : ",0
error BYTE "Wrong Input!, Please enter an alphabet : ",0
msgV BYTE "Character is a vowel!", 0
msgC BYTE "Character is a consonant!", 0
input BYTE ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadChar
call ValidateInput
call WriteChar
mov input, al
call crlf
.IF(input=='a'||input=='e'||input=='i'||input=='o'||input=='u')
mov edx, offset msgV
call WriteString
.ELSEIF(input=='A'||input=='E'||input=='I'||input=='O'||input=='U')
mov edx, offset msgV
call WriteString
.ELSE
mov edx, offset msgC
call WriteString
.ENDIF
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
.IF(al >= 'a' && al <= 'z')
jmp quit
.ELSEIF(al >='A' && al <= 'Z')
jmp quit
.ENDIF
BadInput:
call crlf
mov edx, offset error
call WriteString
call ReadChar
jmp validate
quit:
ret
ValidateInput ENDP
END main
.data
msg BYTE "Enter an alphabet : ",0
error BYTE "Wrong Input!, Please enter an alphabet : ",0
msgV BYTE "Character is a vowel!", 0
msgC BYTE "Character is a consonant!", 0
input BYTE ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadChar
call ValidateInput
call WriteChar
mov input, al
call crlf
.IF(input=='a'||input=='e'||input=='i'||input=='o'||input=='u')
mov edx, offset msgV
call WriteString
.ELSEIF(input=='A'||input=='E'||input=='I'||input=='O'||input=='U')
mov edx, offset msgV
call WriteString
.ELSE
mov edx, offset msgC
call WriteString
.ENDIF
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
.IF(al >= 'a' && al <= 'z')
jmp quit
.ELSEIF(al >='A' && al <= 'Z')
jmp quit
.ENDIF
BadInput:
call crlf
mov edx, offset error
call WriteString
call ReadChar
jmp validate
quit:
ret
ValidateInput ENDP
END main
Let me know in the comment section if you have any question.
Previous Post:
Program that reads a character from keyboard and displays next five and previous five characters.
Comments
Post a Comment