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: max: min: average: the current output is The array has the following values: max: min: average:
it should compile with nasm f elf and gcc in assembly x in snowball
extern printf
section data
mystr: db "The array has the following values: max: d min: d average: dxA ; String format to use decimal followed by newline
myarr: dd
temp: dd
arraysize equ $ myarr
minval: dd
maxval: dd
sumval: dd
section text
global main
main:
; Initialize minimum and maximum with the first value of the array
mov eax,
mov ecx, myarr
mov edx, DWORD ecx
mov minval edx
mov maxval edx
; Loop to find min, max, and sum
xor eax, eax ; A
mov ecx, myarr ; C points to myarr
myloop:
mov ebx, DWORD ecx eax ; Get the value B myarrA
mov temp ebx
; Update minimum value
cmp ebx, minval
jge notmin
mov minval ebx
notmin:
; Update maximum value
cmp ebx, maxval
jle notmax
mov maxval ebx
notmax:
; Update sum value
add sumval ebx
add eax, ; A
cmp eax, arraysize ; Does A arraysize?
jl myloop ; if less, jump to myloop
; Calculate average
mov eax, sumval
mov ebx, arraysize
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, maxval ; Maximum value to print
mov rdxminval ; Minimum value to print
mov rcx rax ; Average value to print
call printf
mov rsp rbp ; Reset rsp
pop rbp ; Restore rbp
mov eax,
ret
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
