Referencing the contents of a memory location. (x86 addressing modes)

后端 未结 2 916
逝去的感伤
逝去的感伤 2020-11-21 06:52

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)

2条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 07:39

    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.

提交回复
热议问题