一条指令可以同时处于两种寻址模式吗? [英] Can an instruction be in two addressing modes at the same time?

查看:124
本文介绍了一条指令可以同时处于两种寻址模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have read the following in the book Programming from the Ground Up:


处理器有一个数字访问数据的不同方式,称为
寻址模式。最简单的模式是立即模式,其中将要访问的数据
嵌入指令本身。例如,如果我们要将寄存器初始化为0,则使用
,而不是给
计算机一个从中读取0的地址,我们将指定立即
模式,并为其指定数字0

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 处于立即模式寄存器寻址模式

Does that mean that for example the instruction mov eax, 123 is in both immediate mode and register addressing mode?

推荐答案

不是整个指令具有特定的寻址模式,而是每个操作数都是单独的。 mov eax,123 的示例中,您会说源是立即操作数,而目的地是寄存器操作数。

It's not the whole instruction that has a certain addressing mode, it's each operand separately. In your mov eax, 123 example, you'd say that the source is an immediate operand, and the destination is a register operand.

或者您可以说该指令的机器代码将使用 mov r, mov 的imm32 编码,如果您想讨论以下形式整个指令需要。 (还有 mov r / m,imm32 形式的 mov ,但是它更长,所以好的汇编程序只会选择

Or you could say that the machine code for that instruction will use the mov r, imm32 encoding of mov, if you want to talk about the form the whole instruction takes. (There's also a mov r/m, imm32 form of mov, but it's longer so a good assembler will only pick that if the destination actually is memory).

但是,当其中一个操作数是一个寄存器时,为方便起见,您可以说该指令使用 [base + index] 寻址模式。但这确实是您在谈论的内存操作数,而不是整个指令。尤其是如果您将寄存器和立即数视为寻址模式,即使不涉及内存地址。

However, when one of the operands is a register, you could for convenience and brevity say "the instruction uses a [base+index] addressing mode" if you want. But really it's the memory operand that you're talking about, not really the whole instruction. Especially if you count register and immediate as "addressing modes", even though there is no memory address involved.

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

Moreover, usually when people say "addressing mode", they're talking about a memory address. Technically in x86, most instructions have one register and one register/memory operand, so the difference between add eax, ecx and add eax, [ecx] is only I think 1 bit in the mod/rm byte (which follows the opcode).

某些指令具有两个内存操作数。例如, push qword [rdi + rax * 8] [rdi + rax * 8] 显式加载存储到 [rsp] 。另一个示例是字符串指令 movs cmps ,它们使用 [rdi] [rsi] 隐含。

Some instructions have two memory operands. For example, push qword [rdi + rax*8] explicitly loads from [rdi + rax*8] and implicitly stores to [rsp]. Another example are the string instructions movs and cmps, which use [rdi] and [rsi] implicitly.

但是没有指令具有两个通用的r / m操作数您可以选择常规寻址模式。因此,x86指令最多具有一个mod / rm字节。

But no instruction has two general r/m operands that let you use an arbitrary choice of the normal addressing modes. So an x86 instruction has at most one mod/rm byte.

立即操作数是否应称为寻址模式,因为数据并非来自任何地方。这是说明的一部分。另外,指令的立即数操作数形式与reg / reg / mem形式的操作码不同。

It's debatable whether an immediate operand should be called an "addressing mode", because the data doesn't come from anywhere. It's part of the instruction. Also, the immediate-operand form of an instruction has a different opcode from the reg, reg/mem form.

还要注意,大多数整数指令可以具有内存源或内存目标有两个操作码:一个用于 op r / m,r ,另一个用于 op r,r / m 。 (例如,请参见 ,以及x86 标签Wiki。)无论如何,和eax,ecx 可以使用两个操作码中的任何一个进行编码,这取决于汇编程序。选择对性能没有影响。

Also note that most integer instructions that can have a memory source or memory destination have two opcodes: one for op r/m, r and one for op r, r/m. (e.g., see the ref manual entry for and, and more links to docs in the x86 tag wiki.) Anyway, and eax, ecx can be encoded with either of the two opcodes, and it's up to the assembler to pick. The choice makes no difference for performance.

这篇关于一条指令可以同时处于两种寻址模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆