I'm coding ASM, and I really don't understand about the rules of mov
, so
mov rax, 100 ; it means that the number 100 is in rax?
mov rax, a ; it means that the value of a is in rax? or is the memory direction?
mov rax, [a] ; it means the value of a? or what?
mov [a], rax ; the direction of memori in a change to rax?
mov rax, rbx ; rbx is now rax?
Sorry if my question is dumb but I'm really confuse... thank you
Since we have, mov rax, 100
as valid, we know it's Intel syntax. Proceeding on and assuming a is a label rather than a macro or equ resulting in a constant:
mov rax, 100 ; Always means put constant 100 in rax
mov rax, a ; Either means put the address of a in rax,
; or put a in rax depending on which assembler.
; For nasm it's always the address of a.
mov rax, [a] ; Always means the 8 byte value stored at a
; for offsets above 2GB, target register must be al, ax, eax, or rax
mov [a], rax ; Put the value of rax in the value stored at a
mov rax, rbx ; Put the value of rbx in rax (no memory access)
mov rax, [rbx] ; Put the value stored where rbx points into rax
I added the last one for completeness. Not doing the math in [] operations here.
However you rarely want to load absolute addresses; you usually want rip-relative, you should normally write the following (NASM syntax):
lea rax, [rel a] ; put address of a into rax
mov rax, [rel a] ; put value at a into rax