Quiz Entry - updated: 2026.07.14
What does cmp %eax, 0x8(%rbp) mean and how is it different from cmp 0x8(%rbp), %eax?
cmp %eax, 0x8(%rbp) computes MEM[rbp+8] - eax; swapping the operands flips the subtraction, which matters for ordered jumps (jl/jg) though not for je/jne.
# Computes: MEM[rbp+8] - eax, sets flags
cmp %eax, 0x8(%rbp)
je label
Reads as: "jump if MEM[rbp+8] == eax"
# Computes: eax - MEM[rbp+8], sets flags
cmp 0x8(%rbp), %eax
je label
Reads as: "jump if eax == MEM[rbp+8]"
For je/jne it doesn't matter — equality is symmetric. But for jl/jg/etc., order matters:
| Code | Meaning |
|---|---|
cmp %eax, 0x8(%rbp) + jl |
jump if MEM[rbp+8] < eax |
cmp 0x8(%rbp), %eax + jl |
jump if eax < MEM[rbp+8] |
Remember: cmp src, dst → condition is about dst relative to src.
Go deeper: