Understanding cmp Instruction in Assembly and Debugging with GDB
I’ve come across a specific instruction sequence that I need help understanding, particularly the comparison (
cmp
) operation and how to break at this point in GDB on an Intel Core i7-11700K Rocket Lake processor . It's low level assembly debugging in C and assembly mix
I’m particularly interested in the cmp
instruction at 0x0000000000001413
. From what I understand, it compares the value stored at [rbp-0x70]
with the value currently in the eax
register.
What exactly is this cmp
operation checking tho?
What happens if the values are not equal?
And how can I set a breakpoint at this comparison line in GDB to inspect the values before the comparison happens?
I tried to break at the memory address 0x0000000000001413
using break *0x0000000000001413
, but I’m not sure if that’s the correct approach4 Replies
The
cmp
, often integer comparison, compare the values then sets a condition flag which jump instructions rely on to make jump decisions. cmp
works by subtraction (cmp a, b == b-a)
Use info registers
in gdb to peek at registers.So if cmp is setting the condition flags based on eax - [rbp-0x70], it must be setting the zero flag (ZF) in case they're equal, which the jne instruction relies on to decide whether to jump or not, correct?
Correct.
Thanks 👍