I have a memory location that contains a character that I want to compare with another character (and it\'s not at the top of the stack so I can\'t just pop
it)
Here is a quick cheatsheet, retrieved from this site. It shows the various methods available for addressing main memory in x86 assembly:
+------------------------+----------------------------+-----------------------------+
| Mode | Intel | AT&T |
+------------------------+----------------------------+-----------------------------+
| Absolute | MOV EAX, [0100] | movl 0x0100, %eax |
| Register | MOV EAX, [ESI] | movl (%esi), %eax |
| Reg + Off | MOV EAX, [EBP-8] | movl -8(%ebp), %eax |
| Reg*Scale + Off | MOV EAX, [EBX*4 + 0100] | movl 0x100(,%ebx,4), %eax |
| Base + Reg*Scale + Off | MOV EAX, [EDX + EBX*4 + 8] | movl 0x8(%edx,%ebx,4), %eax |
+------------------------+----------------------------+-----------------------------+
In your specific case, if the item is located at an offset of 4
from the stack base EBP
, you would use the Reg + Off
notation:
MOV EAX, [ EBP - 4 ]
This would copy the item into register EAX
.