UNIVERSITY OF THE PUNJAB
Third Semester 2016
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 displays next five and previous five characters. If user enters 'a' the next five letters will be b, c, d, e, f and previous letters will be z, y, x, w, v.
Solution:
INCLUDE Irvine32.inc
.data
msg BYTE "Enter an alphabet : ",0
error BYTE "Wrong Input!, Please enter an alphabet : ",0
input BYTE ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadChar
call ValidateInput
call WriteChar
mov input, al
mov ecx, 5
l1:
inc al
.IF(al>'z')
mov al, 'a'
.ENDIF
call crlf
call WriteChar
loop l1
call crlf
mov al, input
mov ecx, 5
l2:
dec al
.IF(al<'a')
mov al, 'z'
.ENDIF
call crlf
call WriteChar
loop l2
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
.IF(al >= 'a' && al <= 'z')
jmp quit
.ENDIF
BadInput:
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
input BYTE ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadChar
call ValidateInput
call WriteChar
mov input, al
mov ecx, 5
l1:
inc al
.IF(al>'z')
mov al, 'a'
.ENDIF
call crlf
call WriteChar
loop l1
call crlf
mov al, input
mov ecx, 5
l2:
dec al
.IF(al<'a')
mov al, 'z'
.ENDIF
call crlf
call WriteChar
loop l2
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
.IF(al >= 'a' && al <= 'z')
jmp quit
.ENDIF
BadInput:
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 alphabetically sorts an array of ten characters.
Comments
Post a Comment