How exactly does the cmpw instruction work? I keep being confused about it... here´s how it works with intel 80386 assembler logic:
#Calculate r11 minus r12 and use that result for the branch#
cmpw r11, r12
# Jump if the result is positive ("r11 is bigger")#
bgt JUMP
# Jump if the result is negative ("r12 is bigger")#
blt JUMP
Am I right or dead wrong? ???
That's pretty much it. On a high level, cmpw just asks "is the first register greater than, less than, or equal to the second register?"
On a lower level, it's subtracting the second register from the first (r11 - r12), and then sets the condition register fields based on the result. If the result is positive, the greater-than bit is set. If the result is negative, the less-than bit is set. If the result is 0, the equal bit is set.
Branches are then taken or not taken based on the condition register field. A bgt branch is taken only if the greater than bit is set. A ble branch is taken if either the less-than or the equal bit are set.
Since you do not specify a condition register field, and you're using integer registers, it will default to using the cr0 field.