UNIVERSITY OF THE PUNJAB
Third Semester 2017
Examination: B.S. 4 Years Programme
Paper: Computer Organization and Assembly Language
Course Code: IT-203 / 21402
Question # 4:
Write a program that inputs 10 digits, stores them into an array and finds the minimum digit. Input Validation: you should input only digits and make sure no other characters can be input.
Solution:
INCLUDE Irvine32.inc
.data
msg BYTE "Enter an integer : ",0
error BYTE "Wrong Input!, Please enter an integer : ",0
result BYTE "Minimum integer is : ",0
array DWORD 10 DUP(?)
.code
main PROC
mov esi, offset array
mov ecx, 10
L1:
mov edx, offset msg
call WriteString
call ReadInt
call ValidateInput
mov [esi], eax
add esi, 4
loop L1
mov ecx, 10
mov esi, offset array
mov eax, [esi]
L2:
.IF([esi]<eax)
mov eax, [esi]
.ENDIF
add esi, 4
loop L2
mov edx, offset result
call WriteString
call WriteDec
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
;ReadInt sets overflow flag if input is invalid
jno quit
BadInput:
mov edx, offset error
call WriteString
call ReadInt
jmp validate
quit:
ret
ValidateInput ENDP
END main
.data
msg BYTE "Enter an integer : ",0
error BYTE "Wrong Input!, Please enter an integer : ",0
result BYTE "Minimum integer is : ",0
array DWORD 10 DUP(?)
.code
main PROC
mov esi, offset array
mov ecx, 10
L1:
mov edx, offset msg
call WriteString
call ReadInt
call ValidateInput
mov [esi], eax
add esi, 4
loop L1
mov ecx, 10
mov esi, offset array
mov eax, [esi]
L2:
.IF([esi]<eax)
mov eax, [esi]
.ENDIF
add esi, 4
loop L2
mov edx, offset result
call WriteString
call WriteDec
quit:
call crlf
call WaitMsg
exit
main ENDP
ValidateInput PROC
validate:
;ReadInt sets overflow flag if input is invalid
jno quit
BadInput:
mov edx, offset error
call WriteString
call ReadInt
jmp validate
quit:
ret
ValidateInput ENDP
END main
Let me know in the comment section if you have any question.
Previous Post:
Write a procedure that reads a text-paragraph from a file and then prints the number of characters on the screen.
Comments
Post a Comment