Write a program that prompts the user for four 32-bit integers, stores them in an array, calculates
Question:
Write a program that prompts the user for four 32-bit integers, stores them in an array, calculates the sum of the array, and displays the sum on the screen. The program also display the smallest and the largest number from the array.
The sample input and output of the program is given below
Please input first numbers: 23,
Please input second numbers: 1
Please input third numbers: 87
Please input fourth numbers: 0
The smallest number is: 0 The largest number is: 87
The summation of the numbers is: 23 + 1 + 87 + 0 = 111
The source code:
.code
main PROC
; get input data from keyboard
mov esi, OFFSET number
; get first number
mov edx, OFFSET str1 call WriteString
call ReadDec
mov [esi], eax
call Crlf
; get second number
add esi, 4
mov edx, OFFSET str2 call WriteString call ReadDec
mov [esi], eax
call Crlf
; get third number
add esi, 4
mov edx, OFFSET str3 call WriteString call ReadDec
mov [esi], eax
call Crlf
; get forth number
add esi, 4
mov edx, OFFSET str4 call WriteString call ReadDec
mov [esi], eax
call Crlf
; to find the smallest
;
mov esi, OFFSET number mov ax, [esi]
mov ecx, 3
next1:
add esi, 4
cmp ax, [esi]
jle next2
mov ax, [esi]
next2:
loop next1
mov smallest, eax
; to find the largest number
;
mov esi, OFFSET number mov ax, [esi]
mov ecx, 3
next4:
add esi, 4
cmp eax, [esi]
jge next3
mov ax, [esi]
next3:
loop next4
mov largest, eax
;
; to find the summation of the numbers
;
mov esi, OFFSET number mov ax, [esi]
mov ecx, 3
next5:
add esi, 4
add ax, [esi]
loop next5
mov sum, eax
; to display the answers
;
mov edx, OFFSET str5 call WriteString
mov eax, smallest
call WriteDec
call Crlf
mov edx, OFFSET str6 call WriteString
mov eax, largest
call WriteDec
call Crlf
mov edx, OFFSET str7 call WriteString
mov esi, OFFSET number mov ecx, 3
mov eax, [esi]
call WriteDec
next6:
mov edx, OFFSET str8 call WriteString
add esi, 4
mov eax, [esi]
call WriteDec
loop next6
mov edx, OFFSET str9 call WriteString
mov eax, sum
call WriteDec
call Crlf
exit
main ENDP
END main
Questions:
- Type the given sample program above and execute it. Input the required data and inspect the output of the program. Trace the program and identify the method used to produce the required output.
- Change the program above so that user can also input signed numbers.
- Change the program above so that user can input hexadecimal numbers.
- Change the program by implementing each function in a procedure. There should be 4 procedures:
- PROC GetNumbers
- PROC Cal Small
- PROC Cal Large
- PROC Cal Sum
- PROC DisplayAnswers How to use procedure:
- To branch to a procedure: CALL (procedure_name)
- To write a procedure :
(procedure_name) PROC
:
(operations)
:
RET
(procedure_name) ENDP
Computer Networking A Top-Down Approach
ISBN: 978-0136079675
5th edition
Authors: James F. Kurose, Keith W. Ross