5

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ShadyBears
  • 3,955
  • 13
  • 44
  • 66

2 Answers2

13

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.
JosephH
  • 8,465
  • 4
  • 34
  • 62
6

You need to learn this AT&T assembly syntax and a little bit of assembly and once you know that stuff, the answers are trivial.

So,

%eax is just the contents of the register.

0x104 is a memory operand, the contents of the memory at address 0x104.

$0x108 is a constant.

(some expression) is a memory operand, the contents of the memory at address some expression.

some constant(some expression) is a memory operand, the contents of the memory at address some expression + some constant.

(%register1, %register2) is, as you may have guessed by now, also a memory operand. The value of the parenthesized expression is register1 + register2.

some constant(%register1, %register2) should be trivial by now as well. Just add the three items and that's the address.

(, %register, some constant) means that you need to multiply the value of the register by the constant.

(%register1, %register2, some constant) should now be intuitive. The value of the parenthesized expression is register1 + register2 * some constant.

Guess now the address of the memory operand like this:

some constant1(%register1, %register2, some constant2).

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180