admin管理员组

文章数量:1391860

If a byte addressable RAM occupies the hexadecimal addresses AOOO to BFFF, then how many KB of storage space is available?

I understand A000 and BFFF to be 16 bit numbers (2 bytes). So each address stores 2 bytes of data. I then converted A000 to decimal format which is 40960 and BFFF which is 49151. Then the number of addresses in this range is (49151 - 40960) + 1 = 8192. 8192 * 2 = 16384 bytes. I divided this by 1024 to get 16KB.

The result seems precise but my book doesn't have answers for this question. Did I do it correctly and is there a more logical way to do this using binary or hexadecimal only?

If a byte addressable RAM occupies the hexadecimal addresses AOOO to BFFF, then how many KB of storage space is available?

I understand A000 and BFFF to be 16 bit numbers (2 bytes). So each address stores 2 bytes of data. I then converted A000 to decimal format which is 40960 and BFFF which is 49151. Then the number of addresses in this range is (49151 - 40960) + 1 = 8192. 8192 * 2 = 16384 bytes. I divided this by 1024 to get 16KB.

The result seems precise but my book doesn't have answers for this question. Did I do it correctly and is there a more logical way to do this using binary or hexadecimal only?

Share Improve this question edited Mar 12 at 4:49 Nate Eldredge 59.4k6 gold badges71 silver badges113 bronze badges asked Mar 12 at 4:34 user529812user529812 11 silver badge
Add a comment  | 

2 Answers 2

Reset to default 2

"Byte addressable" means that each address stores one byte. It's immaterial how many bits are needed to represent the address itself.

To find the number of addressable units (bytes, in this case) between two addresses, when they're inclusive, it's usually convenient to add 1 to the upper address, giving "one past the end"; i.e. the first address not included in the range. Then you simply subtract the lower address from this.

With a little practice, you can do hex arithmetic with paper and pencil, or in your head. It's just like decimal arithmetic but with a somewhat larger addition table for individual digits. Carries work exactly the same.

To add 0xBFFF + 0x1, we would note that 0xF + 0x1 = 0x0 with a carry of 0x1. This quickly tells us 0xBFFF + 0x1 = 0xC000.

Subtracting 0xC000 - 0xA000 is easy, knowing that 0xC is two more than 0xA. So 0xC000 - 0xA000 = 0x2000.

Now we need to divide by 1024 (decimal), which is 2^10 (useful to memorize). This means we must shift right by 10 bits. Each hex digit (nibble) is 4 bits, so shifting right by two hex digits takes care of 8 of those bits, yielding 0x20 (hex). We need to shift right by two more bits, or in other words, divide by 4. One approach is to write 0x20 hex in binary as 0b100000 which makes it easy to shift and get 0b1000 = 0x8 = 8. Or, divide 0x20 by two to get 0x10, then divide by two again to get 0x8 (since 8 is half of 16).

Thus the answer is 8 KiB.

I think, the amount of storage available can depend on the architecture.

Whether the system is byte-addressable or word-addressable. In a byte-addressable architecture, which is common in modern systems, each memory address stores 1 byte of data.

For example, in the given address range A000 to BFFF,

                             A000 (hex) = 40960 (decimal)

                             BFFF (hex) = 49151 (decimal)

The total number of addresses is:

                               (49151−40960)+1=8192 

Since each address stores 1 byte, the total memory is:

                              8192 bytes=8192/1024=8 KB

the total number of addresses is 8192. Since each address corresponds to 1 byte, the total storage is 8192 bytes. Which equals 8 KB.

However, in a word-addressable architecture, each memory address refers to a word instead of a single byte.

If the system has a 16-bit word size, meaning each address stores 2 bytes, then the same address range A000 to BFFF would contain 8192 addresses, but each would store 2 bytes. This results in a total storage of 16 KB instead of 8 KB.

Therefore, the total storage depends on whether the system is byte-addressable or word-addressable, with the latter potentially providing more storage for the same address range depending on the word size.

本文标签: mathCalculating storage space between two memory addressesStack Overflow