为什么 IA32 不允许内存到内存 mov? [英] Why IA32 does not allow memory to memory mov?

查看:24
本文介绍了为什么 IA32 不允许内存到内存 mov?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在英特尔架构 IA32 中,像 movl、movw 这样的指令不允许操作数同时是内存位置.例如,不允许使用指令 movl (%eax), (%edx).为什么?

In Intel architecture IA32, instructions like movl, movw does not allow operands that are both memory locations. For example, instruction movl (%eax), (%edx) is not permitted. Why?

推荐答案

答案涉及更全面地了解 RAM.简单地说,RAM只能处于两种状态,读模式或写模式.如果您希望将 ram 中的一个字节复制到另一个位置,当您从读取切换到写入时,您必须在 RAM 之外有一个临时存储区域.

The answer involves a fuller understanding of RAM. Simply stated, RAM can only be in two states, read mode or write mode. If you wish to copy one byte in ram to another location, you must have a temporary storage area outside of RAM as you switch from read to write.

架构当然有可能拥有这样的 RAM 到 RAM 指令,但这将是一条高级指令,在微代码中将转换为将数据从 RAM 复制到寄存器,然后再复制回 RAM.或者,可以将 RAM 控制器扩展为具有这样一个临时寄存器用于这种数据复制,但它不会为 CPU/硬件交互的增加的复杂性提供太多好处.

It is certainly possible for the architecture to have such a RAM to RAM instruction, but it would be a high level instruction that in microcode would translate to copying of data from RAM to a register then back to RAM. Alternatively, it could be possible to extend the RAM controller to have such a temporary register just for this copying of data, but it wouldnt provide much of a benefit for the added complexity of CPU/Hardware interaction.

值得注意的是,混合内存立方体和高带宽内存等最近的进步是其中 RAM 拓扑变得更像 PCI-e 并且现在直接 RAM 到 RAM 传输的架构可能,但这是由于技术的支持逻辑,而不是 RAM 本身.在 CPU 架构中,这将是一次大块 RAM 的形式,例如 DMA,而不是单个指令的形式,加上 CPU 缓存的行为类似于传统 RAM,因此架构必须将其抽象为根据我原来的解释

It is worth noting that recent advancements such as Hybrid Memory Cube and High Bandwidth Memory are achitectures in which the RAM topology has become more like PCI-e and direct RAM to RAM transfers are now possible, but that is due to the support logic for the technologies, not the RAM itself. In the CPU architecture, this would be in the form of huge blocks of RAM at a time, like DMA, and not in the form of a single instruction, plus the CPU cache behaves like traditional RAM so the architecture would have to abstract it as per my original explanation

根据@PeterCordes 的评论,我最初的理解并不完全正确;x86 实际上确实有一些内存到内存指令.它们对大多数指令(例如 movl 和 movw)不可用的真正原因是为了保持较低的指令编码复杂度,但他们可以实现它们.但是,我的原始答案中的基本思想,即在 RAM 之外以锁存器或寄存器的形式存在一个临时存储位置是正确的,但认为这是这些指令不存在的原因的想法是错误的.甚至 6502 和 8086 等 1970 年代的较旧芯片也具有内存到内存指令,您可以轻松地直接在 RAM 位置执行诸如 INC 之类的操作.这是通过将内存提取直接锁存到 ALU 并再次返回内存而不通过指令集使用的寄存器来实现的.

Per @PeterCordes comment, my original understanding was not entirely correct; x86 does in fact have a few memory to memory instructions. The real reason they are not available for most instructions (such as movl and movw) is to keep instruction encoding complexity low, but they could have implemented them. However, the basic idea in my original answer, that there is a temporary storage location outside of RAM in the form of a latch or register, is correct, but the idea that this is the reason why these instructions don't exist is not. Even older chips from the 1970s such as the 6502 and the 8086 have memory to memory instructions, and you could easily perform operations such as INC directly on a RAM location. This was accomplished by latching the memory fetch directly to the ALU and back out to memory again without going through a register used by the instruction set.

这篇关于为什么 IA32 不允许内存到内存 mov?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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