Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How can i modify the code i have to have the output be The array has the following values: 1 0 2 0 3 0
How can i modify the code i have to have the output be "The array has the following values: max: min: average: all on one line the current output is The array has the following values: max: min: average: as you can see the current average is off by and the array values are missing. DO NOT HARDCODE THE ARRAY VALUES IN MYSTR and the output can all be on oneline
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started