0

I have a simple instruction add $100, 100(%eax, %edx, 8)

I understand that 100(%eax, %edx, 8) resolves to the memory address 100+%eax+(%edx*8) but what I fail to understand is, does it add 100 to this address OR to the value stored at this address.

Issues

  1. In AT&T src, dest is the order. So technically 100(%eax, %edx, 8) should be the destination
  2. Now, it should technically add to the address (and not the value at that addr) but it does not make intuitive sense
  3. Am I wrong to say 100(%eax, %edx, 8) resolves to 100+%eax+(%edx*8) and is it rather that it resolves to (100+%eax+(%edx*8))? Where the outer brackets are dereferencing the address inside it?

Resources I tried checking already

  1. Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2 (2A, 2B, 2C & 2D): Instruction Set Reference, A-Z
  2. http://www.jagregory.com/abrash-zen-of-asm/#mov-move-copy-right-operand-into-left-operand
  3. I'm not exactly sure what this x86 Add instruction is doing
  4. x86 Assembly Memory - What does the "add" instruction do?
  5. https://docs.oracle.com/cd/E19455-01/806-3773/instructionset-19/index.html
  6. http://sourceware.org/binutils/docs-2.17/as/i386_002dMemory.html#i386_002dMemory

Do note, I have not read all of these completely. I do not understand the way they explain perhaps. It is my humble request for you to put it in as much simplicity and detail as possible

Daksh Shah
  • 2,997
  • 6
  • 37
  • 71
  • 2
    Your point (2) is wrong: `add $100, 100(%eax, %edx, 8)` adds to the value at that address, not the address itself. I wonder where you got that wrong information from. (3) is wrong too. The address is `100 + eax + edx * 8` the parentheses are just syntactical, they don't mean anything. – fuz Jan 06 '19 at 21:27
  • @fuz In 3rd, won't you be needing the outer `()`? As they are for dereferencing. If you do not use them, how will add instruction understand that it has to be the `value at that address`? – Daksh Shah Jan 06 '19 at 21:29
  • 2
    What it would mean to add 100 to the address? After adding 100 to the address, then what would happen with the result of the addition? – Raymond Chen Jan 07 '19 at 01:59
  • `addl $100, 55` adds 100 to the dword at absolute address `55`. Unlike NASM syntax, AT&T doesn't always need `()` for a memory operand. Displacements go outside the parens, those are only for registers. Also note that the address-size suffix is required: plain `add` is ambiguous between byte, word, dword, (and qword in 64-bit mode) operand-size. – Peter Cordes Jan 07 '19 at 04:55
  • Found a duplicate that picks apart a complex AT&T addressing mode into its parts with run-time add. The stuff outside the `()` is just the `disp8` / `disp32` part of the addressing mode. – Peter Cordes Jan 07 '19 at 05:07

0 Answers0