So I have a line that does logical compare like:
cmpl $0x1, -0x18(ebp)
. After this it jumps if this is equal, but what exactly does that -0x18(ebp) do?
Let's break it down a bit.
-0x18(ebp)
takes the value stored in the ebp
register, subtracts 0x18
from it, and uses the result as a memory address to read from.
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 set.