Search code examples
assemblyx86memory-addressattaddressing-mode

What value from memory or register do each of the AT&T syntax operands access?


Assume the following values are stored at the indicated memory addresses and registers:

Address    Value            Register     Value
0x100      0xFF             %eax         0x100
0x104      0xAB             %ecx         0x1
0x108      0x13             %edx         0x3
0x10C      0x11


Fill in the following table showing the values for the indicated operands:

Operand           Value    //Solutions at the end of the chapter
%eax              _____    //0x100
0x104             _____    //0xAB
$0x108            _____    //0x108
(%eax)            _____    //0xFF
4(%eax)           _____    //0xAB
9(%eax, %edx)     _____    //0x11
260(%ecx, %edx)   _____    //0x13
0xFC(,%ecx,4)     _____    //0xFF
(%eax, %edx,4)    _____    //0x11

Can someone explain to me how to do this in layman's terms. This isn't hmwk (it's practice problems during certain readings which have the answers @ the end of the chapter), I'm just not understanding the reading.


Solution

  • The general rule for AT&T x86 assembly syntax is

    displacement(offset, relative offset, multiplier) = offset + displacement + ( relative offset * multiplier)
    
    1. %eax refers to actual value of the register(=0x100).
    2. 0x104 refers to the value at address 0x104.
    3. $0x108 refers to the constant value 0x108.
    4. (%eax) refers to the value at address EAX, which is equivalent to 0x100(=0xFF).
    5. 4(%eax) refers to the value at address EAX+4, which is at 0x104.
    6. 9(%eax, %edx) refers to the value at address EAX+9 + EDX, which is at 0x10C.
    7. 260(%ecx, %edx) refers to the value at address ECX+260 + EDX, which is at 0x108.
    8. 0xFC(,%ecx,4) refers to the value at address (ECX*4)+0xFC, which is at 0x100.
    9. (%eax, %edx, 4) refers to the value at address (EAX+(EDX*4), which is at 0x10C.