为什么一步之遥无法读取未对齐的单词? [英] Why is it not possible to read an unaligned word in one step?

查看:110
本文介绍了为什么一步之遥无法读取未对齐的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于CPU的字长允许它寻址存储器中的每个单个字节.
而且考虑到通过 PAE ,CPU甚至可以使用比其字长更多的位来进行寻址.

Given that the word size of a CPU allows it to address every single byte in the memory.
And given that via PAE CPUs can even use more bits than its word size for addressing.

CPU一步无法读取未对齐单词的原因是什么?

What is the reason that a CPU cannot read an unaligned word in one step?

例如,在一台32位计算机中,您可以读取从位置0开始的4字节块,但不能读取从位置1开始的一个字节(可以,但是它需要几个步骤).
为什么CPU不能这样做?

For example, in a 32-bit machine you can read the 4-byte chunk starting at position 0, but you cannot read the one starting at position 1 (you can but it needs several steps).
Why can CPUs not do that?

推荐答案

问题不在于CPU寻址存储器中任何单个字节的能力.但是,内存的粒度不同. 就像奥利(Oli)所说的,这是非常特定于体系结构的,但是存储芯片通常通过其数据总线的宽度来解决.意味着给定地址代表其数据总线的完整字".

The problem is not with the ability of the CPU to address any single byte in the memory. But it is the memory that has not the same granularity. Like Oli said, this is very architecture-specific, but memory chips are often addressed by their data bus wideness. Meaning that a given address represents a full "word" of their data bus.

让我们以32位CPU为例,其中32位宽的数据总线连接到存储设备.当CPU要访问地址0x00000000处的字时,它确实希望访问字节0123.但是对于内存芯片,这由单个地址0x00000000表示.

Let's take the example of a 32 bits CPU, with a 32 bits-wide data bus connected to a memory device. When the CPU wants to access to the word at address 0x00000000, it really wants to access to the bytes 0, 1, 2 and 3. For the memory chip however, this is represented by the single address 0x00000000.

现在,当CPU要访问地址0x00000001上的字时,它确实希望访问字节1234.对于内存芯片,这由地址0x00000000上的一个单词和地址0x00000001上的一个单词表示.

Now when the CPU wants to access to the word at address 0x00000001, it really wants to access to the bytes 1, 2, 3 and 4. For the memory chips however, this is represented by a piece of the word at address 0x00000000 and a piece of the word at address 0x00000001.

因此需要两个总线周期.

Hence the need for two bus cycles.

编辑:添加一些接线图

为了说明这一点,以下两种寻址方式都被反对:

To illustrate this, here are both addressing scheme opposed:

请注意RAM芯片地址中的位移.

Notice the bit shift in the addresses of the RAM chip.

地址将如下所示:

// From the RAM point of view
@0x00000000: Bytes 0x00000000 to 0x00000003
@0x00000001: Bytes 0x00000004 to 0x00000007

要访问双字@0x00000001,您会看到无法直接寻址.您需要向RAM芯片询问地址0x000000000x00000001上的两个双字.

To access to the dword @0x00000001, you can see that no direct addressing is possible. You need to ask the RAM chip for both dwords at addresses 0x00000000 and 0x00000001.

这篇关于为什么一步之遥无法读取未对齐的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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