需要多少位来寻址这么多内存?
我正在学习编程基础课程,目前我正在学习有关计算机组织和位操作的章节 - CPU(ALU、CU、寄存器等)如何工作。
我对二进制语言有相当好的理解。我理解符号/数值格式/1的补码、2的补码等。
在书中我了解到半字节= 4位,8位= 1字节接下来是一个字 - 通常是分组的:8位,16位、32 位或 64 位(等等),所有这些对我来说都很有意义。这是我的作业问题,这对我来说有点困惑:
“计算机有 64 MB 内存,每个字有 4 个字节。需要多少位来寻址内存中的每个字?”
嗯,我现在很困惑。这本书只是告诉我一个单词通常是 8 的倍数。 但是我知道 1 个字节 = 8 位,所以既然有 4 个字节,1 个字节 = 8 个字节,那么认为 4 个字节 x 8 位 = 32 位是否正确?这就是答案吗?
I'm taking a programming fundamentals course and currently I'm on the chapter where it talks about computer organization and operations on bits - how the CPU (ALU, CU, registers, etc.) works.
I have a fairly good understanding of the binary language. I understand sign/magnitude format/ 1's complement, 2's complement, etc.
In the book I've learned that a nibble = 4 bits, 8 bits = 1 byte next is a word - which is usually in groups: 8 bits, 16 bits, 32 bits or 64 bits (so on), and all this makes perfect sense to me. Here's my homework question which is kind of confusing to me:
"A computer has 64 MB of memory, Each word is 4 bytes. How many bits are needed to address each single word in memory?"
Well, I'm confused now. The book just told me that a word is typically in multiples of 8.
However I know that 1 byte = 8 bits, so since there are 4 bytes and 1 byte = 8 bytes, would it be correct to think that 4 bytes x 8 bits = 32 bits? Is this the answer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1 位地址可以寻址两个字 (0, 1)。
2 位地址可以寻址四个字(00、01、10、11)。
3 位地址可以寻址 8 个字(000、001、010、011、100、101、110、111)。
所以首先回答:你有多少字?然后回答:您的地址需要多少位才能寻址它们?
A 1-bit address can address two words (0, 1).
A 2-bit address can address four words (00, 01, 10, 11).
A 3-bit address can address eight words (000, 001, 010, 011, 100, 101, 110, 111).
So first answer: How many words do you have? Then answer: How many bits does your address need in order to address them?
64MB = 67108864 字节/4 字节 = 内存中的 16777216 个字,因此每个字可以用 24 位寻址(第一个字的地址为 000000000000000000000000,最后一个字的地址为 111111111111111111111111)。另外,2 得到 24 = 16777216,因此需要 24 位来寻址存储器中的每个字。
要求是用一个地址(以位为单位)表示每个内存字,以便可以表示每个字。
例如,要表示4个字,需要4个地址,2加到2就是4,所以需要两个位。 00是第一个字的地址,01是第二个字的地址,10是第三个字的地址,11是第四个字的地址。
对于8个字,需要8个地址,2加到3就是8,所以需要3位。 000、001、010、011、100、101、110、111 是 8 个地址。
64MB = 67108864 Bytes/4 Bytes = 16777216 words in memory, and each single word can thus be addressed in 24 bits (first word has address 000000000000000000000000 and last has address 111111111111111111111111). Also 2 raised to 24 = 16777216, so 24 bits are needed to address each word in memory.
The requirement is to represent each memory word with an address, which is in bits, in such a way that each and every word can be represented.
For example, to represent 4 words, you need 4 addresses, 2 raised to 2 is 4, so you need two bits. 00 is the address of the first word, 01 is the address of the second word, 10 is the address of the third word, and 11 is the address of the 4th word.
For 8 words, you need 8 addresses, and 2 raised to 3 is 8, so 3 bits are needed. 000, 001, 010, 011, 100, 101, 110, 111 are the 8 addresses.
不,这不是答案。如果你的计算机有 64 MB 内存,每个字有 4 个字节,那么你的内存中有多少个字?您需要多少位来寻址每个字(表示从 0 到字数 - 1 的数字所需的位)。
No, that's not the answer. If your computer has 64 MB of memory and each word is 4 bytes, how many words are there in your memory? How much bits would you need to address each word (bits needed to represent a number from 0 to number of words - 1).
公式为:
log(内存大小/可寻址单元大小)/log 2
示例1:
需要多少个地址位来寻址 16GB 内存,其中每个可寻址单元的宽度为 1 字节?
Ans: log(16*1024*1024*1024/1)/log2 = 34 位
示例2:
需要多少个地址位来寻址 16GB 内存,其中每个可寻址单元的宽度为 2 个字节?
Ans: log(16*1024*1024*1024/2)/log2 = 33 位
示例3:
需要多少个地址位来寻址 64MByte 的内存,其中每个可寻址单元的宽度为 4 个字节?
Ans: log(64*1024*1024/4)/log2 = 24 位
示例3:
需要多少个地址位来寻址 16MByte 的内存,其中每个可寻址单元的宽度为 1 字节?
答:log(16*1024*1024/1)/log2 = 24 位
The formula being:
log (Memory Size/Addressable Unit Size) / log 2
Example1:
How many address bits are required to address 16GBytes of memory, where each addressable unit is 1 byte wide?
Ans: log(16*1024*1024*1024/1)/log2 = 34 bits
Example2:
How many address bits are required to address 16GBytes of memory, where each addressable unit is 2 bytes wide?
Ans: log(16*1024*1024*1024/2)/log2 = 33 bits
Example3:
How many address bits are required to address 64MBytes of memory, where each addressable unit is 4 bytes wide?
Ans: log(64*1024*1024/4)/log2 = 24 bits
Example3:
How many address bits are required to address 16MBytes of memory, where each addressable unit is 1 byte wide?
Ans: log(16*1024*1024/1)/log2 = 24 bits