Search results
Results From The WOW.Com Content Network
25. According to my understanding cmpl compares unsigned. It does both, in a way. The difference in signed vs. unsigned is here the usage of the jump instructions. For >, there is ja for unsigned and jg for signed (jump if above and jump if greater). For <, there is jb for unsigned and jl for signed (jump if below and jump if less).
cmpl subtracts -0x10(%ebp) from $0x7 and modifies flags: AF CF OF PF SF ZF. If memory at -0x10(%ebp) equals immediate 0x7 then the flag ZF is set. This is below EBP so it's probably a local variable, if this is an un-optimized build using EBP as a frame pointer. jne 80484db means that if the two compared numbers are different (ZF=0), jump to ...
The instruction (cmpl) has an l suffix, so it's dealing with a 4 byte quantity. So what's actually happening is that it reads a 4 byte number from the address %ebp - 0x30 and checks whether it's zero. (The $ prefix means it's an immediate value, not an address. This is why 0x0 is taken literally and not dereferenced.)
the results of CMP is changing the values of ZF and CF, this is some examples to understand very much CMP instruction. Example 1: if AX < BX. MOV AX,5. MOV BX,8. CMP AX,BX. Result : ZF and CF set to ==> "ZF = 0" and "CF = 1". Example 2 : if AX > BX. MOV AX,8. MOV BX,5.
In Intel syntax, this would be cmp al, bl. After this point, the following jumps would be taken: JB, because 0 < 255. JNA, because ! (0 > 255) JNL, because ! (0 < -1) JG, because 0 > -1. Note how in this particular example the signedness mattered, e.g. JB is taken but not JL. Runnable example with assertions.
cmpl %esi, %edi ; compare the value of esi to edi, and set flags movl %esi, %eax ; move the value of esi into eax cmovge %edi, %eax ; if flags indicate greater than or equal to (i.e., SF == OF), ; then move the value of edi into eax So the C translation for your assembly code would be:
Also, the machine instructions are likely to be generated (by LLVM) way after the C++ code was parsed by clang (which is probably even unaware that the target platform is x86-64). The machine code generation module could be honouring clang's request for a "generic atomic load", and not risking merging other instructions with it.
Therefore, cmpl $0x1, -0x18(ebp) reads the value stored at the memory address calculated from -0x18(ebp) and subtracts $0x1 from it, setting various flags based on that calculation (e.g. setting the zero flag ZF to 1 if the subtraction results in 0). The various jmp instructions then determine whether to jump or not based on the flags that were ...
The instruction cmpl %edx, %eax should set the flag as 0-5, which is -5. j. Nope. Remember that in AT&T syntax the operand order is source, destination. You've got eax = 5 and edx = 0, so cmpl %edx, %eax sets the flags based on 5-0, after which the jge should jump.
JS jumps if the SIGN bit in EFLAGS is 1. According to intel manual: Sign flag — Set equal to the most-significant bit of the result, which is the sign bit of a signed integer. (0 indicates a positive value and 1 indicates a negative value.) So, answering to your question, cmpl $1, (%eax) will set the sign bit if eax - 1 is negative.