Question: How can i modify the code i have to have the ouput be The array has the following values: 1 0 2 0 3 0

How can i modify the code i have to have the ouput be "The array has the following values: 102030405060 max: 60, min: 10, average: 35". the current output is " The array has the following values: max:60, min: 10, average:38
extern printf
section .data
mystr: db "The array has the following values: max: %d, min: %d, average: %d",0xA,0 ; String format to use (decimal), followed by newline
myarr: dd 10,20,30,40,50,60
temp: dd 0
array_size equ ($ - myarr)/4
min_val: dd 0
max_val: dd 0
sum_val: dd 0
section .text
global main
main:
; Initialize minimum and maximum with the first value of the array
mov eax, 0
mov ecx, myarr
mov edx, DWORD [ecx]
mov [min_val], edx
mov [max_val], edx
; Loop to find min, max, and sum
xor eax, eax ; A =0
mov ecx, myarr ; C points to myarr
myloop:
mov ebx, DWORD [ecx +4* eax] ; Get the value B = myarr[A]
mov [temp], ebx
; Update minimum value
cmp ebx, [min_val]
jge not_min
mov [min_val], ebx
not_min:
; Update maximum value
cmp ebx, [max_val]
jle not_max
mov [max_val], ebx
not_max:
; Update sum value
add [sum_val], ebx
add eax, 1 ; A++
cmp eax, array_size ; Does A == array_size?
jl myloop ; if less, jump to myloop
; Calculate average
mov eax, [sum_val]
mov ebx, array_size
cdq
idiv ebx ; Divide sum by number of values
; Now print the result out
push rbp ; Preserve rbp
mov rbp, rsp ; Set rbp as stack frame pointer
mov rdi, mystr ; Format of the string to print
mov rsi, [max_val] ; Maximum value to print
mov rdx,[min_val] ; Minimum value to print
mov rcx, rax ; Average value to print
call printf
mov rsp, rbp ; Reset rsp
pop rbp ; Restore rbp
mov eax, 0
ret

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!