(請教) 記憶體中放置的位置是對齊的(Aligned),則定址字組需要幾個位元

假設某一計算機中有 1 Giga Bytes 的記憶容量,每個字組有 32 位元,若其在記憶體中放置的位置是對齊的(Aligned),則定址字組需要28個位元。 若不需對齊,則需要30個位元。

為什麼呢?謝謝
1GBytes = 2^30 Bytes
Aligned: 存取單元32 bit (2^2 Bytes)是排列好的, 只需定址至每個存取單元的開頭, 故 2^30 Bytes / 2^2 Bytes = 2^28
Unaligned: 每個Byte都可能是存取單元的開頭, 需定址至每個Byte, 故 2^30 Bytes / 1 Byte = 2^30
1tac wrote:
1GBytes = 2...(恕刪)


謝謝

原來是
1GB=1024MB
1MB=1024KB
1KB=1024Byte

2的10次方等於1024
所以是1024*1024*1024
不對的說法
有沒有對齊不會影響

定址方法是處理器決定的
資料有沒有對齊是程式員決定的
資料有沒有對齊,處理器並不在乎
沒對齊的話,就分兩次抓就好,沒什麼

所以,並不存在什麼
有對齊就採用 word addressing
沒對齊就採用 byte addressing
這種事

一個 word 是 32 bits,即 4 bytes
1 GiB = 2^30 bytes = 2^28 words
所以
byte addressing 需要 30 位元
word addressing 需要 28 位元
Stallings wrote:

一個 word 是 32 bits,即 4 bytes
1 GiB = 2^30 bytes = 2^28 words
所以
byte addressing 需要 30 位元
word addressing 需要 28 位元



編譯器不同?

以前我用Turbo C, 1 word= 2 bytes

所以已 1 byte 為單位 定址所有記憶體, 須 30位元
所以已 2 bytes 為單位 , 須 29位元(兩個兩個一數)
所以已 4 bytes 為單位 , 須 28位元(四個四個一數)
sansen wrote:
編譯器不同?以前我用Turbo...(恕刪)
word 在不同場合會有不同定義
x86 / x64 組合語言,1 word 固定 16 bits
不過通常說的 word 是指,對處理器而言最自然的寬度
說白話就是一般暫存器的寬度啦
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!