How do you detect when a register is zero and then when you decrement it , it wraps to 0FFh. Is there a flag you check or do I have to check for 0FFh?
Posted on 2003-11-24 14:53:39 by x86asm


; It is S (sign) flag you need.

.loopff:
dec ecx
jns .loopff

; here ecx = -1 ($ffffffff)


Regards.
Posted on 2003-11-24 15:01:36 by JohnFound



; It is S (sign) flag you need.

.loopff:
dec ecx
jns .loopff

; here ecx = -1 ($ffffffff)


Regards.


I thought that as well but you see the problem is that there is a possibility that the value will be above 80h even after decrementing it.

Hey I got an idea, (I should have told you this) the value is a byte, so would it work if I zero extend it into a 32-bit register and then do what you suggested, so even if the byte is above 80h it won't tamper with the sign flag?

For example 80h becomes 00000080h and then decrement and test for sign?
Posted on 2003-11-24 15:03:57 by x86asm
hi,

If the value range is always contained within a byte, you can use this:



mov ecx,0ffh
.loopff: sub cl,1
jnc .loopff


Notice the "sub" (not "dec") to set the carry flag according to the result.

Cheers,
h.
Posted on 2003-11-24 16:52:04 by hitchhikr
Say:

cmp eax,80h
jae XXXXXXXXh ; jump above or equal
Posted on 2003-11-25 15:45:54 by mrgone