[Solved] My code should find the minimum value in an array. In a procedure shown below, the assembly code compares 2 values in an dword array and jumps to setMin part when the second value is below the first. For some reason my program does not jump to setMin even when I can clearly see in the registers during debugging that it should jump. In result - the min value that is printed out is completely off and I don't know where its from (but that's entirely a different issue).
Here is the code:
; Find the minimum value in the array
; in : arr of 10 dword values
; minIs = "Minimum value is "
; out : eax
;----------------------------------
mov esi, OFFSET arr ; arr adress
mov eax, [esi] ; current min is 1st value
mov ecx, 10 ; loop counter
Lcompare:
add esi, 4 ; next value
mov ebx, [esi]
cmp eax, ebx ; compare 2 values
jb setMin ; Jump if not Below to next
jmp next
setMin:
mov eax, [esi] ; sets new minimum value
next:
loop Lcompare
mov edx, OFFSET minIs
call WriteString ; "Minimum value is "
call WriteInt ; display min value
call Crlf
The arr input: 194, 102, 167, 157, 107, 140, 158, 148, 173, 194
The output:
Minimum value is +1701602643
I would really appreciate if someone could point out why the program does not enter setMin:
after jb setMin
but instead goes straight to next:
.
And as a bonus could someone explain why I am getting that output instead of one of the values from the array?