Question

cmp %al, %cl
js x

I'm confused on what the js (jump on sign) is doing. Is it saying that if al is positive and cl is negative vice versa then jump?

Also, what happens if %cl is 0?

Was it helpful?

Solution

JS will jump if the sign flag is set (by an earlier instruction). CMP will always modify the flags by performing a subtraction, in this case %cl - %al.
(This is AT&T syntax, so cmp %cl, %al is the same as Intel syntax cmp al, cl)

Because of the operand-size of the instructions, the sign will be bit 7 of the expression %cl-%al (which is thrown away; EFLAGS is updated just like sub, but not al.)

If al == 0, then the temporary value will be cl exactly and the sign will be the sign of the register cl. Thus a jump is taken if cl is negative.

Here's a reference for all the conditional jumps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top