assemblyx86att

What does JS do in Assembly x86?


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?


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 %al, %cl is the same as Intel syntax cmp cl, al)

    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.