I'm trying to make a code in assembly with arq. x86 using NASM.
In this code I should return the difference between the highest value and lowest value of an array, as below.
However, while rolling it is returning 14 for the example below and the correct one would be 18 (20-2). Could you help me find my mistake? Thank you very much in advance.
section .data
array: DB 2,4,6,8,10,12,14,16,18,20
size EQU $-array
section .text
global _start
_start:
mov eax,[array]
mov ebx,[array]
xor ecx,ecx
mov edx,size
jmp compara
maior:
mov eax,[array+ecx]
jmp volta_maior
menor:
mov ebx,[array+ecx]
jmp volta_menor
compara:
cmp ecx,edx
jnle fim
cmp [array+ecx],eax
jge maior
volta_maior:
cmp [array+ecx],ebx
jle menor
volta_menor:
inc ecx
jmp compara
fim:
sub eax,ebx
mov ebx,eax
mov eax,1
int 0x80