The difference between cmpl and cmp

I am trying to understand the assembly in order to solve the riddle. However, I came across the following instructions:

0x0000000000401136 <+44>: cmpl $0x7,0x14(%rsp) 0x000000000040113b <+49>: ja 0x401230 <phase_3+294> 

What I think he does is this: The value 0x14 (% rsp) is -7380. According to my understanding, cmpl compares unsigned. A jump is also in progress. So it may be that (unsigned) -7380> 7 (unsigned) 7380> 7 β†’ jump

Actually, I don’t want him to jump. But is this the right explanation or not? Am I flipping arguments?

Also, if you have any tips on how to manipulate this jump!

+8
c assembly x86 x86-64
source share
2 answers

In my understanding cmpl compared unsigned.

He does it somehow.

The difference in signed vs. unsigned is to use jump commands.

For > for unsigned and jg there is ja for the signed ones (jump, if higher, and jump, if more).

For < for unsigned and jl there is jb for signing (jump, if lower, and jump, if less).

To be precise, here is the meaning of several transition commands:

For unsigned comparisons:

 JB/JNAE (CF = 1) : Jump if below/not above or equal JAE/JNB (CF = 0) : Jump if above or equal/not below JBE/JNA (CF = 1 or ZF = 1) : Jump if below or equal/not above JA/JNBE (CF = 0 and ZF = 0): Jump if above/not below or equal 

For signed comparisons:

 JL/JNGE (SF <> OF) : Jump if less/not greater or equal JGE/JNL (SF = OF) : Jump if greater or equal/not less JLE/JNG (ZF = 1 or SF <> OF): Jump if less or equal/not greater JG/JNLE (ZF = 0 and SF = OF): Jump if greater/not less or equal 
+14
source share

I do not think x86 actually has an instruction called CMPL . This is probably part of your assembler syntax to give clues about operands or something else (like JZ and JE ).

From the intel manual on what it does:

Compares the first source operand with the second source operand and sets the status flags in the EFLAGS register according to the results. Comparison is performed by subtracting the second operand from the first operand and then setting the status flags in the same way as the SUB instruction. When a value is used as an operand, it is decrypted by value to the length of the first operand.

The sign is specified implicitly, due to two additional representations of numbers.

How to manipulate a jump? If you are sure that the jump should do the same thing that it does, you just need to change the JA to JBE .

+1
source share

All Articles