Hey all, i'm really confused what the heck is going on my program. It is a simple program that loops through an array of ints and finds the minimum. Here's the snippet of the code:
loopBody: mov bh, [edx][esi] ;Assigns element to bh to compare.
cmp bh, bl ; loops through, compares current min to next array element
jl setMin ;If less than, then initiates setMin
contLoop: add esi, 4 ;Increments esi by 4 for next array element
loop loopBody ;back to loop top
jmp theEnd ;if loop is done, go to theEnd
setMin: push ebx ;saves ebx, containing bl (min) and bh (comparison)
mov bl, bh ;sets new min
mov bh, 0 ;zeroes out bh so memory ebx is bl
mov [eax], ebx ;move edx value to eax
pop ebx ;gathers min and comparison agian
mov bl, bh ;sets bl to new min since overwritten, continues.
jmp contLoop ;go back to loop
I'm watching the registers. I entered a 5 value array as followed:
100
125
150
175
200
It works fine, but when it has 150, ebx = 00009664 (bh = 96 and bl = 64) but the cmp bh, bl shows true for this statement and calls the jl statement. I can't make heads or tails of it. Anyone know what's going on?