Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
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
0x0000000000001410 <+241>: mov eax,DWORD PTR [rbp-0x74]
0x0000000000001413 <+244>: cmp DWORD PTR [rbp-0x70],eax
0x0000000000001416 <+247>: jne 0x149d <main+382>
0x000000000000141c <+253>: lea rsi,[rip+0xbf7] # 0x201a
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 approach
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 👍
CONTRIBUTE TO THIS THREAD