方括号在x86汇编中是什么意思? [英] What do square brackets mean in x86 assembly?
问题描述
我刚接触汇编,并且有一些非常基本的问题.
I'm very new to assembly, and have some very basic questions.
这四个命令有什么区别?
What is the difference between these four commands?
mov ebx, eax
mov [ebx], eax
mov ebx, [eax]
mov [ebx], [eax]
他们说方括号的意思是获取地址的值".但是,那第一行实际上是做什么的呢?它不会将eax的价值转移到ebx吗?如果可以,那么括号的意义是什么?
They say that the brackets mean "get the value of the address". But what, then, does that very first line really do? Does it not move the value of eax into ebx? If it does, then what are the point of the brackets?
推荐答案
让我们举一个非常简单的示例,并假设我们有一个只有两个寄存器(EAX和EBX)的CPU.
Let's make a very simple example and imagine we have a CPU with only two registers, EAX and EBX.
mov ebx,eax
mov ebx, eax
只需将eax
中的值复制到ebx
寄存器
Simply copies the value in eax
to the ebx
register
| EAX : 0123456 | ----> | EAX : 0123456 |
| EBX : 0000000 | ====> | EBX : 0123456 |
现在让我们添加一些内存空间
Now let's add some memory space
ADDRESS VALUE
000000 6543210
000004 5189784
000008 1698791
00000C 9816517
000010 9816875
000014 5498156
mov [ebx],eax
mov [ebx], eax
将eax
中的值移动到ebx
中包含的内存地址.
Moves the value in eax
to the memory address contained in ebx
.
| EAX : 0123456 | --no--> | EAX : 0123456 |
| EBX : 0000008 | --change--> | EBX : 0000008 |
ADDRESS VALUE VALUE
000000 6543210 ----> 6543210
000004 5189784 ----> 5189784
000008 1698791 ====> 0123456
00000C 9816517 ----> 9816517
000010 9816875 ----> 9816875
000014 5498156 ----> 5498156
mov ebx,[eax]
mov ebx, [eax]
将值从eax
中包含的内存地址移动到ebx
.
Moves the value from the memory address contained in eax
to ebx
.
| EAX : 0000008 | ----> | EAX : 0000008 |
| EBX : 0123456 | ====> | EBX : 1698791 |
ADDRESS VALUE
000000 6543210
000004 5189784
000008 1698791
00000C 9816517
000010 9816875
000014 5498156
mov [ebx],[eax]
mov [ebx], [eax]
最后,您会认为会将值从eax
中包含的内存地址移动到ebx
中包含的内存地址.
This, finally, you would think would move the value from the memory address contained in eax
to the memory address contained in ebx
.
| EAX : 0000008 | --no--> | EAX : 0000008 |
| EBX : 000000c | --change--> | EBX : 000000c |
ADDRESS VALUE VALUE
000000 6543210 ----> 6543210
000004 5189784 ----> 5189784
000008 1698791 ----> 1698791
00000C 9816517 ====> 1698791
000010 9816875 ----> 9816875
000014 5498156 ----> 5498156
但是x86体系结构不允许这种组合. 您不能在内存之间移动.
But this combination is disallowed by the x86 architecture. You cannot move from memory to memory.
因此,括号的使用等效于 取消引用 操作.
The use of brackets is therefore equivalent to a dereferencing operation.
这篇关于方括号在x86汇编中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!