Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why 16-bit address with 12-bit offset results in 4KB page size?

I'm reading the "Modern Operating System" book. And I'm confused about the "Page Size".

In the book, the author says,

The incoming 16-bit virtual address is split into a 4-bit page number and 12-bit offset. With 4 bits for the page number, we can have 16 pages, and with 12 bits for the offset, we can address all 4096 bytes within a page.

Why 4096 bytes? With 12 bits, we can address 4096 entries within a page, correct. But, one entry is an address (in this case, address size = 16 bits). So I think we can address 4096(entry) * 16(bit) = 4096(entry) * 2(byte) = 8KB, but why the book says that we can address 4096 (bytes) ?

Thanks in advance! :)

like image 665
Mouhong Lin Avatar asked Sep 12 '10 05:09

Mouhong Lin


3 Answers

This is assuming byte-addressed memory (which almost every machine made in the past 30 years uses), so each address refers to a byte, not an entry or address or any other larger value. To hold a 16-bit value, you'll need two consecutive addresses (two bytes).

More than 30 years ago, there used to be machines which were word addressed, which worked like you surmise. But such machines had a tough time dealing with byte-oriented data (such as ASCII characters), and so have fallen out of favor. Nowadays, things like byte addressability, 8-bit bytes and twos-complement integers are pretty much just assumed.

like image 90
Chris Dodd Avatar answered Dec 31 '22 10:12

Chris Dodd


The 12 bits are an offset within a page. The offset is in bytes, not addresses. 2^12 is 4096.

like image 28
Mark Ransom Avatar answered Dec 31 '22 09:12

Mark Ransom


Because with 12 bit, we can address 2^12=4096 slots. Each slot represents an address which size is 1 byte in byte-addressable memory. Hence the total size is 4096*1=4096 bytes = 4KB.

like image 32
hqt Avatar answered Dec 31 '22 11:12

hqt