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

16,034

Solution 1

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.

Solution 2

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

Share:
16,034
Mouhong Lin
Author by

Mouhong Lin

C# Programmer. Blog: http://blog.mouhong.me Weibo: https://weibo.com/linmouhong Email: dylan.lin [AT] live.com

Updated on June 05, 2022

Comments

  • Mouhong Lin
    Mouhong Lin about 2 years

    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! :)

  • dbasnett
    dbasnett almost 14 years
    I worked on a large mainframe in the 70' and 80's that was word addressed. They offered an option that added hardware that allowed you to address bytes or BCD characters directly.
  • Armada
    Armada over 9 years
    Thanks very much. This answer cleared up a lot of uncertainty I was having with an assignment.
  • Peter Camilleri
    Peter Camilleri over 7 years
    There are current processors that use word addressing, but they all tend to be specialized embedded types like a digital signal processor (DSP). I once worked on a project where the smallest addressable unit was 16 bits. On that machine sizeof(char) == sizeof(int) == 1. It was wasteful for character strings, but this application had only very modest usage of 8 bit data so the waste was not an issue.