基本使用的x86汇编和YASM立即数(方括号)的 [英] Basic use of immediates (square brackets) in x86 Assembly and yasm
问题描述
假如我有以下声明:
section .bss
buffer resb 1
和这些说明如下:
mov al, 5
mov [buffer], al
mov bl, [buffer]
mov cl, buffer
我是正确的理解是BL将包含值5,和CL将包含变量的内存地址缓存
?
我感到困惑
- 移动立即到寄存器,
- 移动寄存器到直接(在发生什么,数据或地址?)和
- 移动立即到寄存器没有括号
- 例如,
MOV CL,缓冲
VSMOV CL [缓冲]
- moving an immediate into a register,
- moving a register into an immediate (what goes in, the data or the address?) and
- moving an immediate into a register without the brackets
- For example,
mov cl, buffer
vsmov cl, [buffer]
更新:看完后的反应,我想下面的总结准确的:
UPDATE: After reading the responses, I suppose the following summary is accurate:
假设声明
阵列RESB 0
在存在.bss段
。我的理解是:Assume the declaration
array resb 0
exists undersection .bss
. My understanding is that:-
MOV EDI,阵列
会将零数组索引的内存地址EDI
。 -
MOV [EDI],3
会将值3到数组 的零指数 - 在
添加EDI,3
,EDI
现在包含数组的第3个指数的内存地址 -
MOV人,[阵列]
把该数据的零指数为人
。 -
MOV人,[阵列+ 3]
放置数据的第三个指数为人
。 -
MOV [人],[阵列]
是无效的,无论出于何种原因。 -
MOV阵列,3
是无效的,因为你不能说嘿,我不喜欢的偏移量,阵列
存储,所以我会叫它3 -
MOV [阵列] 3
把值3到数组的第零指标。
mov edi, array
puts the memory address of the zeroth array index inedi
.mov [edi], 3
puts the VALUE 3 into the zeroth index of the array- after
add edi, 3
,edi
now contains the memory address of the 3rd index of the array mov al, [array]
puts the DATA at the zeroth index intoal
.mov al, [array+3]
puts the DATA at the third index intoal
.mov [al], [array]
is invalid, for whatever reason.mov array, 3
is invalid, because you can't say "Hey, I don't like the offset at whicharray
is stored, so I'll call it 3"mov [array], 3
puts the value 3 into the zeroth index of the array.
请注明如果这些都是假的。
Please mention if any of these is false.
推荐答案
事实上,你的思想是correct.That是,BL将包含5和CL缓冲器的存储器地址(实际上标签缓冲器是存储器地址本身)
Indeed, your thought is correct.That is, bl will contain 5 and cl the memory address of buffer(in fact the label buffer is a memory address itself).
现在,让我解释一下你提到的操作之间的差异:
Now, let me explain the differences between the operations you mentioned:
-
移动立即到是可以做到用一个寄存器
MOV章,IMM
。什么可能是令人困惑的是,标签如缓冲区是包含即时数值本身地址。
moving an immediate into a register can be done using
mov reg,imm
.What may be confusing is that labels e.g buffer are immediate values themselves that contain an address.
您不能真正移动寄存器到直接,因为眼前的值是常量,如
2
或FF1AH
。什么,你可以做的是移动寄存器其中常数点to.You可以像MOV [常量],章
。You cannot really move a register into an immediate, since immediate values are constants, like
2
orFF1Ah
.What you can do is move a register to the place where the constant points to.You can do it likemov [const], reg
.您也可以使用间接寻址像
MOV REG 2,[REG1]
提供REG1指向有效的位置,而且将转移由REG1指向的值REG2。You can also use indirect addressing like
mov reg2,[reg1]
provided reg1 points to a valid location, and it will transfer the value pointed by reg1 to reg2.因此,
MOV CL,缓冲
将移动缓冲区的地址以CL(这可能会或可能不会给出正确的地址,因为CL只有一个字节长),而MOV CL [缓冲]
将得到的实际值。So,
mov cl, buffer
will move the address of buffer to cl(which may or may not give the correct address, since cl is only one byte long) , whereasmov cl, [buffer]
will get the actual value.- 当你用[A],那么你参考价值的地方,一个点to.For例如,如果是
F5B1
,然后按[A]是指在地址F5B1的内存的 - 标签的地址,即价值如
F5B1
。 - 值不必被引用为[章],因为寄存器不必addresses.In事实上,寄存器可以被认为是即时值。
存储在寄存器- When you use [a], then you refer to the value at the place where a points to.For example, if a is
F5B1
, then [a] refers to the address F5B1 in RAM. - Labels are addresses,i.e values like
F5B1
. - Values stored in registers do not have to be referenced to as [reg] because registers do not have addresses.In fact, registers can be thought of as immediate values.
这篇关于基本使用的x86汇编和YASM立即数(方括号)的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- For example,
- 例如,