2
Address    Value            Register     Value
0x100      0xFF             %rax         0x100
0x104      0xAB             %rcx         0x1
0x108      0x13             %rdx         0x3
0x10C      0x11


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

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

I found a similar question on this site, but I still don't understand how 9(%rax, %rdx) works. I thought it was supposed to be 9+100+3 = 112 and find the value at address 0x112, but there is no address 0x112 given to us? And in the similar problem I found here: Hard time understanding assembly language it seems that with 260(%rcx, %rdx) we needed to convert the value to hexadecimal? But that didn't work for 9(%rax, %rdx). Same with (%rax, %rdx,4). I still get 112. How does that lead to address 0x10C to get a value of 0x11?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 3
    9+3 _decimal_ is 12, and 12 in hexadecimal is (0x)C NOT 0x12 (which would instead be 18, and 9+3 is NOT 18). rax is 0x100 not 100 dec, and 0x100 + 0xC = 0x10C. Similarly, 3 \* 4 is 12 dec = 0xC. 260 dec = 0x104. – dave_thompson_085 Jun 26 '21 at 08:43

1 Answers1

2

9(%rax, %rdx)

  • value of %rax is 0x100
  • value of %rdx is 0x3

While you are correct that the answer should be the contents of memory at 9 + %rax + %rdx, in this instance, 9 is in decimal, while 0x100 and 0x3 are in Hex. You need to convert the values into either hex or dec to add them, and then convert back to hex for the address.

  • 0x3 in Decimal is 3
  • 3 + 9 = 12 (decimal)
  • 12 in Hex is 0xC
  • 0x100 + 0xC = 0x10C

So look at memory at that address, because 9(%rax, %rdx) is AT&T addressing mode syntax for a memory operand. (An LEA instruction would put the address itself into the destination, but any other usage would reference the memory there.)

(9 = 0x9 so hex addition would be more straightforward,
as long as you know that 0x3 + 0x9 = 0xc not 0x12.)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847