Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does JS do in Assembly x86?

Tags:

x86

assembly

att

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?

like image 418
user3128376 Avatar asked Feb 19 '14 06:02

user3128376


People also ask

What does JB do in assembly?

The JB instruction branches to the address specified in the second operand if the value of the bit specified in the first operand is 1. The bit that is tested is not modified. No flags are affected by this instruction.

What is JA in x86?

JA is used for jumping if the last "flag changing" instruction was on unsigned numbers. but on the other hand, JG is used for jumping if the last "flag changing" instruction was on signed numbers.

What is Jae instruction?

jae means Jump if above or equal. It will jump if the carry flag is equal to 0.

What is ECX in assembly language?

CX is known as the count register, as the ECX, CX registers store the loop count in iterative operations. DX is known as the data register. It is also used in input/output operations. It is also used with AX register along with DX for multiply and divide operations involving large values.


1 Answers

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.

like image 81
Aki Suihkonen Avatar answered Sep 29 '22 22:09

Aki Suihkonen