3

Memory Segment Below.

On the first add instruction (add eax, 3), it moves the pointer for eax 3 spots to the right.

Thus, EAX = 12, 17, A3, 00. (This I understand)

But, on the second add instruction (add ebx, 5), it actually adds the value 5 to ebx,

making EBX = 12, 17, A3, 05.

Why is that?

(Little Endian)

enter image description here enter image description here

Asia x3
  • 606
  • 2
  • 16
  • 37
  • 2
    _Thus, EAX = 12, 17, A3, 00."_ In nasm syntax `mov eax, var1` means `eax = address of var1`, not `eax = value at var1`. As for why the least significant byte of `ebx` ends up with the value 5; the byte at `var1+3` is initially 0. 0 + 5 = 5. – Michael Mar 19 '17 at 13:34

1 Answers1

3

'add reg, (something)' adds that value to the register, period. The difference you are seeing is how you are using the registers.

As you are doing 'mov ebx,[eax]' you are using the value in eax as a pointer, because you are de-referencing it with the square brackets.

Lambchops
  • 91
  • 2