Question: In Assembly (NASM), I am in an endless loop. My error is in block .L5, lines 45 & 46. Can't solve. conceept is to find

In Assembly (NASM), I am in an endless loop. My error is in block .L5, lines 45 & 46. Can't solve. conceept is to find minium and maximum values of signed array

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,1 ; 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 [array1],rsi ; update array1's next element

mov rax,rsi ; update rax to next array value

cmp rcx,1 ; check if last element

je .L6 ; if last element, jump to end of loop

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

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!