Question
Am in endless loop - cannot find error: Code in Assembly, NASM. Purpose is to find min & max of signed array. ( PLEASE test
Am in endless loop - cannot find error:
Code in Assembly, NASM. Purpose is to find min & max of signed array. ( PLEASE test your reply first).
------------------------------------------------------------------
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: ; max 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] jmp .L5 .L3: ; min cmp rdx,qword[array1] ; compare accumulator with array element jge .L4 ; if array1 element less than jl .L5 ; if array1 element greater than, drop and jump to end of loop mov rdx,qword[array1] ; move min [rsi] to rdx mov [minval],rdx ; save [minval] .L4: add rsi,8 ; update to next element cmp rcx,0 ; check if last element je .L6 ; if last element, jump to end of loop loop .L1 ; next element
.L5: add rsi,8 ; update to next address mov rbx,[rsi] ; move value of rsi to rbx cmp rbx,0 ; check if value is zero, if yes jump to end of loop je .L6 ; if equal jump to end mov [array1],rbx ; update array1 next element with value at rsi mov rax,rsi ; update rax to next array value loop .L1 ; next element
.L6: ; 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