Question
I am unable to find my error and need help - NASM Assembly. My minval not updatinng. Array1 gives a value of (gdb) x/gd &array1
I am unable to find my error and need help - NASM Assembly. My minval not updatinng. Array1 gives a value of (gdb) x/gd &array1 0x402000 : 4202504 Please help.
Problem: omputer Organization, Assembly Language Find Min/Max Array values Given an array of signed quadwords, find the minimum and maximum values stored in that array. The starter code given contains an array named array1, and two variables, minval and maxval for storing the minimum and maximum values respectively. Upon completion of the program, minval and maxval should contain the appropriate values.
global _start ; exposes program entry point to the linker section
.text ;
start of code segment
_start:
xor rax,rax ; initialize to zero
xor rdx,rdx ; initialize to zero
xor rbx, rbx ; initialize to zero
xor rsi,rsi ; clear
mov rsi,array1 ; address of 1st element
.L1:
mov rcx,array1_len ; loop counter
cmp qword[array1],rax ; compare array element with rax
jge .L2 ; if element greater than or equal, go to maxval
jmp .L3 ; if negative go to minval
.L2: ; maxval
cmp qword[array1],rbx ; compare next pos. index to maxval
jl .L4 ; if [array1] element less than maxval drop
mov rbx,qword[array1] ; move max rsi to rbx
mov [maxval],rbx ; save [maxval]
.L3: ; minval
cmp rdx,qword[array1] ; compare accumulator with array element
jg .L4 ; if array1 element great than, drop
mov rdx,qword[array1] ; move min [rsi] to rdx
mov [minval],rdx ; save minval
.L4:
add rsi,8 ; update to next element
mov [array1],rsi ; verify next element
mov rax,[array1] ; update rax to next array value
loop .L1 ; next element
; End the program
mov rax, 0x3c ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system call
section .data ; start of initialized data segment
array1 dq 45,21,-7,17,-33,25,0,-14,35,-33,42,18,-3,7,-34
array1_len equ ($-array1)/8
section .bss ; start of uninitialized data segment
minval resq 1
maxval resq 1
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