11
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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user3128376
  • 974
  • 6
  • 17
  • 40

1 Answers1

21

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57