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

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:

; Programming 6 i1 INCLUDE Irvine 32.inc i;data segment . data stri BYTE  Please input first numbers: ,0 str2 BYTE  Plea

.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:


  1. 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.
  2. Change the program above so that user can also input signed numbers.
  3. Change the program above so that user can input hexadecimal numbers.
  4. 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:
  5. To branch to a procedure: CALL (procedure_name)
  6. To write a procedure :

(procedure_name) PROC

:

(operations)

:

RET

(procedure_name) ENDP



 

;Programming 6. INCLUDE Irvine32.inc ; data segment .data " Please input first numbers: ",0 " Please input second numbers: ", 0 " Please input third numbers: ", 0 " Please input fourth numbers: ",0 " The smallest number is: ",0 " The largest number is: ",0 " The summation of the numbers is: ",0 + ",0 = ",0 4 dup (?) strl str2 str3 str4 str5 str6 TE str7 str8 str9 number dword smallest dword largest dword sum dword

Step by Step Solution

3.52 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

model tiny data str1 BYTE Please ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!