Michael Smith
Michael Smith

Reputation: 3447

What is the difference between jmp and ja?

From my understanding jmp does an unconditional jump, whereas ja jumps if the value is unsigned. Am I getting this right?

An example would be greatly appreciated.

Upvotes: 4

Views: 8835

Answers (2)

Simon Richter
Simon Richter

Reputation: 29598

ja means "jump if Carry Flag unset and Zero Flag unset".

The cmp instruction is really the same as the sub instruction (i.e. it subtracts its arguments), except that the result is not saved but only the condition flags are updated.

If we were comparing unsigned integers, subtracting (a-b) sets the Carry Flag if b is greater than a, and the Zero Flag if b is equal to a, so if neither of these flags is set, it follows that a is greater than b.

If we wanted a comparison of signed numbers, we'd have to compare the Sign Flag (i.e. the topmost bit of the result) to the Overflow Flag, and check that the Zero Flag is unset, which is what the jg instruction does.

Thus, the cmp instruction does not care about whether the arguments are signed or unsigned. This distinction is only in how the flags are interpreted afterwards.

Source

Upvotes: 6

Barmar
Barmar

Reputation: 781131

You're correct that jmp does an unconditional jump.

Your description of ja is incorrect, though. It does a conditional jump, based on the result of the most recent cmp operation. It jumps if the first operand was greater than the second operand, using unsigned comparison rather than signed comparison. jg would use signed comparison.

Upvotes: 7

Related Questions