Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing unsigned 32-bit values

Status
Not open for further replies.

jorgander

Programmer
Jul 15, 2003
11
US
i'm sort of a newbie to assembly, but have been a C programmer for a long time, so i'm not clueless about this stuff...

that being said, i am trying to compare a value agaist -1, (that is, 4294967295). for some reason, the sign bit is not getting set when i do this. i've tried js and jl, but neither work. i've tried switching the order of the operands and using jns and jge, but they obviously don't work either.

the code is:

cmp DWORD PTR [esp + ecx], edi
jns blah

edi holds 4294967295, and [esp + ecx] holds a smaller value (during my testing it usually contains something like 25600, but that's irrelevent). but for almost any value of [esp + ecx], the sign bit should be set after the cmp instruction. is there something i'm missing here? i'm using masm 6.15 if that has anything to do with it.
 
never mind; i didn't know to use ja instead of jg, etc.
 
What's happening is you're setting the flags as though you had subtracted edi from [esp + ecx], and if you subtract -1 from something, it's the same as adding 1. So the answer is one greater than whatever was in [esp + ecx], and unless the thing in [esp + ecx] is so big it's nearly reached the negative numbers (i.e. 07FFF....h), or already is negative, then the result is not going to have a set sign bit...

Hope that helps.

(If it's any consolation, I always get hopelessly mixed up between ja and jg, and have to go and look up which flag bits they actually test....)
 
when i was first learning the instruction set, i didn't read the descriptions of all the different jumps. i just assumed there were more or less the same (e.g. ja and jg) and just had different mnemonics. when i read the fine print, it became a little clearer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top