-4

I have looked at many threads regarding this topic and all are confusing. I have not seen a visual for any of the answers that can help me.

I do not understand the difference between all these statements:

mov eax, ebx
mov [eax],ebx
mov eax, [ebx]

If anyone can create a table with values and show me, that would be great.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Csaas33
  • 5
  • 2

1 Answers1

7

In Intel's syntax, adding square brackets around register names, labels, or constants (*) will result in the data in memory pointed to by the register/label being used for the operation.

(*) This answer by Ross Ridge deals with some of the peculiarities of MASM when using the square brackets.

mov rax, rbx

copies the contents of rbx into rax.


mov rax, [rbx]

loads the qword referenced by rbx into rax.


mov [rax], rbx

stores the contents of rbx to the qword in memory pointed to by rax.


In C-style syntax the expressions above can be written as:

rax = rbx
rax = *rbx
*rax = rbx
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
hyred-
  • 176
  • 5
  • @Sep Roland So what if I do this, mov eax, 2 | mov [eax[, 2 – Csaas33 Aug 03 '21 at 01:35
  • @Csaas33 Assuming that last "[" is a typo, next is what these instructions do: `mov eax, 2` **loads** the value 2 into the `EAX` register (`EAX`changes), and `mov [eax], 2` would **store** the value 2 in the memory location whose address is contained in `EAX` (`EAX` does not change). But MASM would complain because it does not know the *size* of the memory location! You have a choice of `mov byte ptr [eax], 2`, `mov word ptr [eax], 2`, and `mov dword ptr [eax], 2`. – Sep Roland Aug 05 '21 at 15:48