简体   繁体   English

从大于指令中可用大小的内存中加载

[英]Loading from memory whose size is larger than the available size in an instruction

Processors these days are mostly 32 or 64 bit. 这些天的处理器大多是32位或64位。 This means that the instructions they process have this size. 这意味着他们处理的指令具有此大小。

We often hear that a 32-bit operating system is limited to 4GB=(2^32 bits) of RAM due to the fact that the length of a RAM address needs to hold inside 32 bits. 我们经常听到,由于RAM地址的长度需要保持在32位以内,因此32位操作系统限于4GB =(2 ^ 32位)RAM。

But in fact, when we look at how instructions look, you often have way less than 32 bits to load a word. 但是实际上,当我们看一下指令的外观时,加载字的方式通常少于32位。

Let's take the x86 mov instruction, you have an opcode, a source and a destination address. 让我们以x86 mov指令mov ,您有一个操作码,一个源和一个目标地址。

My question is, how can we possibly load something from a 32 bit long address? 我的问题是,我们怎么可能从32位长的地址中加载某些内容?

Do we always need to have a pointer to that address in a place in memory that has a smaller address that can be used in an instruction? 我们是否总是需要在内存中某个地址中有一个指向该地址的指针,该地址可以在一条指令中使用?

Thanks 谢谢

The premise of this question is false. 这个问题的前提是错误的。 A processor being "x-bit" does not mean all instructions are x bits long. 处理器为“ x位”并不意味着所有指令的长度均为x位。 It can mean that, particularly on RISC architectures, which x86 is not an example of. 可能意味着,特别是在RISC架构上,x86 并不是示例。 These days on x86, an instruction can anywhere from 1 byte to 15 bytes long (the upper limit used to be lower). 这些天在x86上,一条指令的长度可以从1字节到15字节不等(上限以前较低)。

So x86 has no trouble with putting addresses (or other constants) in its instructions. 因此,x86在其指令中放置地址(或其他常量)没有任何麻烦。 Plenty of space. 足够的空间。 Note, by the way, that it never needs both a source and a destination address, that is simply not encodable. 请注意,顺便说一句,它永远不需要源地址目的地址,这简直是不可编码的。 At least one of them has to be a register in most instructions, and in the couple of instructions that really do have two memory addresses, the addresses are implicit. 在大多数指令中,其中至少有一个必须是寄存器,而在这对确实具有两个内存地址的指令中,这些地址是隐式的。

On some other architectures, you're absolutely right: the instruction can not be long enough to accommodate a full address (because they are the same size, and that would leave no opcode bits). 在其他一些体系结构上,您是完全正确的:指令的长度不能足够容纳一个完整的地址(因为它们的大小相同,并且不会留下操作码位)。 A common solution is offering an addressing mode that is relative to the instruction pointer, and then you can store a full address "nearby" if you need an absolute address. 一种常见的解决方案是提供一种相对于指令指针的寻址模式,然后,如果需要绝对地址,则可以存储完整的地址“附近”。

Processors these days are mostly 32 or 64 bit. 这些天的处理器大多是32位或64位。 This means that the instructions they process have this size. 这意味着他们处理的指令具有此大小。

This is untrue. 这是不正确的。 The "bitness" of a processor, when referring to processors that come from the x86 family, refers to their ability of executing instructions from the AMD64/EM64T (often generalized as x86-64 or just x64) instruction set. 当指代来自x86系列的处理器时,处理器的“位”指的是它们执行AMD64 / EM64T(通常统称为x86-64或仅x64)指令集的指令的能力。 These instructions extend the already existing instructions to work on 64-bit registers, and - generally - allow the processor to use 64-bit addresses, which widens the address space to 2^64 bytes. 这些指令扩展了已经存在的指令以在64位寄存器上工作,并且-通常-允许处理器使用64位地址,这将地址空间扩展为2 ^ 64字节。 However, most real implementations of these CPUs don't have physical 64 address lines, although the virtual address space is still obviously 64-bit wide. 但是,尽管虚拟地址空间显然仍然是64位宽,但是这些CPU的大多数实际实现都没有物理的64条地址线。 Incidentally, most of the instructions still operate on 32-bit data, and 32-bit operands are the default even in x64. 顺便说一句,大多数指令仍然对32位数据进行操作,即使在x64中,32位操作数也是默认值。 There is only one instruction that can take a 64-bit operand - mov . 只有一条指令可以采用64位操作数mov

The processors from the x86 family all have variable-size encoding of instructions. x86系列的处理器都具有可变大小的指令编码。 This means that every instruction's size depends on the type of the instruction, and the used operands. 这意味着每条指令的大小取决于指令的类型以及使用的操作数。 The same instruction can take only two bytes when operating on registers ( xor eax, eax ), or five bytes when specifying a full (32-bit) immediate operand ( xor eax, 0xf0f0f0f0 ). 在寄存器上进行操作时,同一条指令只能占用两个字节( xor eax, eax ),而在指定完整(32位)立即数操作数( xor eax, 0xf0f0f0f0 )时只能占用五个字节。

Processors these days are mostly 32 or 64 bit. 这些天的处理器大多是32位或64位。 This means that the instructions they process have this size. 这意味着他们处理的指令具有此大小。

This assumption is wrong for x86 because instructions can have a length of 1 byte up to 15 bytes. 对于x86,此假设是错误的,因为指令的长度可以为1个字节,最大为15个字节。 You can check the intel manual on how to decode an instruction. 您可以查看有关如何解码指令的英特尔手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM