Electronic – Size of program counter


Can we say anything about the program counter by looking at the size of a memory chip?

I think the program counter is part of the microprocessor and memory is external. How can we comment about the program counter by looking at the size of the memory?

For example, I had a question in one of my tests:

A memory chip of 8kB has a data bus of 4 bits. What will be the size of the program counter?

Best Answer

You can't really make assumptions about the program counter (PC) width from the memory address width.

There have been many many different memory architectures historically, and new ones will undoubtedly be dreamed up. At a very basic level for the simplest of machine, the PC contains the memory address during instruction fetches, so is the same width as that address. However, there are many tricks, even in early machines, that make this more complicated.

For example, machines with virtual memory can logically address more memory than physically exists. The PC would then be wider than the address bus. On a more modern processor operating in "32 bit" mode, the PC would be 32 bits wide. However, that means the PC can only address 4 GB of memory. Many modern machines can address more physical memory than that.

There are a variety of segmentation schemes. The PC is more limited, and some other register holds the upper address bits of the segment the PC is operating in. Jumps within the same segment work normally by loading the PC, but moving between segments is more complicated and requires additional instructions and the like. The actual physical memory could be both larger or smaller than the what the PC can address natively.

Then there are Harvard architectures and the like where there isn't just one memory space, or where execution isn't possible from all of memory.