Computer Organization and Architecture SCR 1043 Semester 2, 07/08 Programming 6: Interactive Programming Sample Program Write a complete assembly language to have input and output as 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 Instruction: ;Programming 6 ; INCLUDE Irvine32.inc ; ;data segment .data str1 BYTE " Please input first numbers: ",0 str2 BYTE " Please input second numbers: ",0 str3 BYTE " Please input third numbers: ",0 str4 BYTE " Please input fourth numbers: ",0 str5 BYTE " The smallest number is: ",0 str6 BYTE " The largest number is: ",0 str7 BYTE " The summation of the numbers is: ",0 str8 BYTE " + ",0 str9 BYTE " = ",0 number dword 4 dup (?) smallest dword ? largest dword ? sum dword ? .code main ; PROC int 3 ; get input data from keyboard ; mov esi, OFFSET number ; get first number mov edx, OFFSET str1 call WriteString call ReadDec mov [esi], eax 1 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 2 next5: add add loop mov esi, 4 ax, [esi] next5 sum, eax ; to display the answers ; mov edx, OFFSET str5 call WriteString mov eax, smallest call WriteDec call Crlf mov call mov call call edx, OFFSET str6 WriteString eax, largest WriteDec Crlf mov call edx, OFFSET str7 WriteString mov mov mov call esi, OFFSET number ecx, 3 eax, [esi] WriteDec mov call add mov call edx, OFFSET str8 WriteString esi, 4 eax, [esi] WriteDec loop next6 mov call mov call call edx, OFFSET str9 WriteString eax, sum WriteDec Crlf next6: exit main ENDP END main Exercise: 1. Type the given sample program below 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. 3 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: a. b. To branch to a procedure: CALL (procedure_name) To write a procedure : (procedure_name) PROC : (operations) : RET (procedure_name) ENDP 4