我如何在 asm 中使用 MOV?

How can I use MOV in asm?

我正在编写ASM,我真的不了解mov的规则,所以

    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?

抱歉,如果我的问题很愚蠢,但我真的很困惑... 谢谢

因为 mov rax, 100 有效,所以我们知道它是 Intel 语法。继续并假设 a 是一个标签而不是一个宏或 equ 导致一个常量:

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

为了完整起见,我添加了最后一个。此处未在 [] 运算中进行数学运算。

但是你很少想加载绝对地址;你通常想要 rip-relative,你通常应该写下面的(NASM 语法):

lea rax, [rel a] ; put address of a into rax
mov rax, [rel a] ; put value at a into rax