gpt4 book ai didi

assembly - 一条指令可以同时处于两种寻址模式吗?

转载 作者:行者123 更新时间:2023-12-03 09:32:38 25 4
gpt4 key购买 nike

我在《从头开始编程》一书中阅读了以下内容:

Processors have a number of different ways of accessing data, known as addressing modes. The simplest mode is immediate mode, in which the data to access is embedded in the instruction itself. For example, if we want to initialize a register to 0, instead of giving the computer an address to read the 0 from, we would specify immediate mode, and give it the number 0.

In the register addressing mode, the instruction contains a register to access, rather than a memory location. The rest of the modes will deal with addresses.



这是否意味着例如指令 mov eax, 123是立即模式还是寄存器寻址模式?

最佳答案

并不是整个指令都有一定的寻址方式,而是每个操作数都是分开的。 在您的 mov eax, 123例如,您会说源是立即数操作数,而目标是寄存器操作数。

或者你可以说该指令的机器码将使用 mov r, imm32 encoding of mov ,如果你想谈论整个指令的形式。 (还有一个 mov r/m, imm32 形式的 mov ,但它更长,所以一个好的汇编器只会在目标实际上是内存时才选择它)。

但是,当操作数之一是寄存器时,为了方便和简洁,您可以根据需要说“指令使用 [base+index] 寻址模式”。但实际上,您正在谈论的是内存操作数,而不是整个指令。特别是如果您将寄存器和立即数视为“寻址模式”,即使不涉及内存地址。

此外,通常当人们说“寻址模式”时,他们指的是内存地址。从技术上讲,在 x86 中,大多数指令都有一个寄存器和一个寄存器/内存操作数,因此 add eax, ecx 之间的区别和 add eax, [ecx]只是我认为 mod/rm 中的 1 位字节(跟在操作码之后)。

有些指令有两个内存操作数。例如,push qword [rdi + rax*8][rdi + rax*8] 显式加载并隐式存储到 [rsp] .另一个例子是字符串指令 movscmps , 使用 [rdi][rsi]含蓄地。

但是没有指令有两个通用的 r/m 操作数,可以让您使用任意选择 the normal addressing modes .所以一条 x86 指令最多有一个 mod/rm 字节。

立即操作数是否应该称为“寻址模式”是有争议的,因为数据不是来自任何地方。这是指令的一部分。此外,指令的立即操作数形式与 reg、reg/mem 形式具有不同的操作码。

另请注意,大多数具有内存源或内存目标的整数指令都有两个操作码:一个用于 op r/m, r一个用于 op r, r/m . (例如,参见 the ref manual entry for and ,以及更多指向 标签维基中的文档的链接。)无论如何,and eax, ecx可以使用两个操作码中的任何一个进行编码,这取决于汇编程序的选择。选择对性能没有影响。

关于assembly - 一条指令可以同时处于两种寻址模式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44861768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com