x86汇编MOV指令-寄存器到寄存器和存储器到存储器 [英] x86 Assembly MOV instruction - Register to Register and Memory to Memory

查看:386
本文介绍了x86汇编MOV指令-寄存器到寄存器和存储器到存储器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,MOV指令允许寄存器进行寄存器移动,而无法进行存储器之间的移动.为什么是这样?

我在此处阅读了该记忆不允许移动到内存,因为这会使CPU复杂化,并且任何给定指令的RAM必须处于读取模式或写入模式.任何人都可以对此进行扩展吗?为什么RAM必须处于读模式和写模式?如何在单个指令中从寄存器而不是从RAM读取和写入?

解决方案

因为Intel是这样设计的,并且即使您使用or al, [si]时,灵活地编码or [di], [si]也会使指令更长.

您读到的有关读或写模式的信息没有意义,因为or [rdi], rax进行读-修改-写操作.因此,除了少数几条可以读取一个位置并写入另一个位置的指令(见下文)之外,总会有两种指令同时执行.

当英特尔设计x86时,他们决定通过只允许为每条指令的一个操作数选择寻址模式来限制指令编码的复杂性.另一个寄存器操作数由字节中的3位选择,这也选择了寻址模式. (或者3位作为操作码的一部分,或者3位填充在其他地方.当前的x86指令编码有很多特殊情况...)

x86-64增加了一个额外的位来使寄存器数量增加一倍,但没有改变任何基本内容. (不过,它确实添加了相对于RIP的地址.)

https://stackoverflow.com/tags/x86/info 中查看英特尔手册的链接.

>

大多数x86指令采用以下形式之一

op r, r/m32
op r/m32, r

r是gp寄存器之一,而r/m32是寄存器或内存操作数,具体取决于寻址模式.

尽管两个版本共享相同的助记符,但它们通常是不同的操作码.因此,从硬件/机器语言POV来看,内存源和内存dest版本是两个单独的指令.对于各种特殊情况,mov本身具有许多不同的操作码. (尤其是如果您算是要移入/移出控制寄存器.)

正如人们在评论中指出的那样,有一些指令可以读取和写入存储器,其中至少一个操作数具有隐式位置,而这些隐式位置没有以常规的mod/rm寻址模式编码进行编码.

  • movs:字符串移动. (除非与rep一起使用,否则速度非常慢)
  • push r/m32(例如push [rax]).

It's known that the MOV instruction allows register to register moves while memory to memory moves are not possible. Why is this?

I've read here that memory to memory moves are disallowed because it complicates the CPU and that RAM has to be in either a read mode or write mode with any given instruction. Is anyone able to expand on this? Why does RAM have to be in either read mode and write mode? How is it possible to read and write from registers but not from RAM within a single instruction?

解决方案

Because Intel designed it that way, and having the flexibility to encode or [di], [si] would have made the instruction longer even when you were using or al, [si].

What you read about read or write mode doesn't make sense, because or [rdi], rax does a read-modify-write. So there always were instructions that did both, even apart from the few instructions that could read one location and write another (see below).

When Intel designed x86, they decided to limit the complexity of instruction encoding by only allowing a choice of addressing modes for one operand per instruction. The other register operand is selected by 3 bits in the byte that also selects an addressing mode. (Or 3 bits as part of the opcode, or 3 bits stuffed somewhere else... current x86 instruction encoding has so many special cases...)

x86-64 added an extra bit to double the amount of registers, but didn't change anything fundamental. (It did add RIP-relative addressing, though.)

See links to Intel manuals from https://stackoverflow.com/tags/x86/info.

Most x86 instructions take one of these forms

op r, r/m32
op r/m32, r

The r being one of the gp registers, and the r/m32 being a register or memory operand, depending on the addressing-mode.

The two versions are usually different opcodes, even though they share the same mnemonic. So from a hardware / machine-language POV, the memory source and memory dest versions are two separate instructions. mov itself has many different opcodes, for various special cases. (especially if you count move to/from control registers.)

As people note in comments, there are instructions that both read and write memory, with at least one of the operands having an implicit location not encoded in the usual mod/rm addressing mode encoding.

  • movs: string move. (don't use except with rep, it's super slow)
  • push r/m32 (e.g. push [rax]).

这篇关于x86汇编MOV指令-寄存器到寄存器和存储器到存储器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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