为什么必须取消引用数据标签才能在其中存储内容:Assembly 8086 FASM [英] Why do you have to dereference the label of data to store something in there: Assembly 8086 FASM
问题描述
考虑以下示例:
mov al, [variable1]
这是有道理的,因为您在寄存器 al 中保存了变量 1 的内容(因此取消了对它的引用).
This makes sense, as you save in the register al the content (thus dereferencing it) of variable1.
现在考虑这个例子:
mov dword L6, 1
这是不正确的;正确的形式是
This isn't correct; the correct form is
mov dword [L6], 1
如果我们将 1 移动到内存中,我应该告诉它存储在那个地址而不是内容中.假设您要告诉某人去某个地方参加派对,您需要向他们提供派对的地址,而不是那里的人.
If we're moving 1 to memory, I should tell it to be stored at that address and not at the content. Say you're telling someone to go to a certain place for a party, you'd give them the address of the party and not the people in there.
那么,这是为什么呢?
推荐答案
x86 没有内存间接数据寻址.这是 0 和 1 级间接与作为立即数的符号地址之间的区别,而不是 1 与 2.
x86 doesn't have memory-indirect data addressing. It's the difference between 0 and 1 levels of indirection vs. the symbol address as an immediate, not 1 vs. 2.
与 C 不同,在 FASM(和 NASM)语法中,提及裸符号名称是地址作为值.
Unlike C, in FASM (and NASM) syntax, mentioning a bare symbol name is the address as a value.
例如mov eax, symbol
设置 EAX = 放置该标签的地址,使用 mov eax, imm32
指令,而不是从内存中加载.
e.g. mov eax, symbol
sets EAX = the address where you put that label, with a mov eax, imm32
instruction, not a load from memory.
当然mov符号,eax
不能工作,因为立即数不能作为目标,只有[disp32]
寻址模式.
Of course mov symbol, eax
can't work because an immediate constant can't be a destination, only a [disp32]
addressing mode.
如果我将 mov 视为 write ,它会更有意义.我可以将 mov
视为写入而不是移动"吗?
if I think of mov as write it makes a lot more sense. Can I think of
mov
as write instead of "moving?
是的.mov 只是从源操作数复制到目标操作数.这就是目标必须指向内存或寄存器的原因.但源操作数可以是立即数、寄存器或内存.
Yes. mov just copies from the source operand to the destination operand. That's why the destination has to be pointed-to memory or a register. But the source operand can be an immediate, register, or memory.
(当然,对于单个 mov
指令,您不能同时拥有 src 和 dst 内存;有 不同形式用于不同类型的操作数.)
(Of course you can't have both src and dst be memory for a single mov
instruction; there are different forms for different kinds of operands.)
FASM 和 NASM 中的 asm 符号有点像 C char arr[]
.
你不能做 arr = x;
- asm 等价物是 mov arr, al
这也不合法(在 FASM 和 NASM 语法中).
You can't do arr = x;
- the asm equivalent is mov arr, al
which isn't legal either (in FASM and NASM syntax).
但是你可以做 *arr = x;
在 asm 中是 mov [arr], al
But you can do *arr = x;
which in asm is mov [arr], al
仅供参考:MASM 语法不同:mov sym, al
不是在所有上下文中用作数字占位符的符号,而是与 mov [sym], al
和括号是可选的,没有寄存器没有意义.
FYI: MASM syntax is different: instead of symbols working as a placeholder for a number in all contexts, mov sym, al
is a store the same as mov [sym], al
and the brackets are optional and meaningless without a register.
如果您看到任何 MASM 示例或 GCC/clang .intel_syntax noprefix
输出;这就是正在发生的事情.
If you see any MASM examples or GCC/clang .intel_syntax noprefix
output; that's what's going on.
这篇关于为什么必须取消引用数据标签才能在其中存储内容:Assembly 8086 FASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!