Relationship between the size of CPU registers and main memory

computer-architecturecpumemory

I have read this post however I still have a question.

I understand that saying 32 bit processor implies registers of size 32 bit long each of which can hold up to 2^32 data. What does it mean saying 32 bit processor support 4GB addressable memory? What if I have 8GB RAM, does it mean it is more than necessary?

Best Answer

each of which can hold up to 2^32 data

No. A 32 bit register can hold 32 bits of data. One possible use of that would be for an integer that can range from 0 to (2^32)-1, i.e. 0 through 4,294,967,295, inclusive.

What does it mean saying 32 bit processor support 4GB addressable memory?

"Memory" is too vague a term these days. When anyone talks about "memory" they need to make clear whether they're talking about physical memory (generally RAM) or virtual memory. For both of these there is an additional concept of "address space" - thus we have physical address space (the set of physical addresses within which all RAM on the machine must fit) and virtual address space (the set of virtual addresses within with all defined virtual memory exists).

When address translation is enabled - and it is enabled very shortly after boot on any modern OS, and remains that way until shutdown - all addresses referenced by the CPU are interpreted as virtual addresses. A 32-bit x86 CPU is limited to only 4 GB of virtual address space. there are a couple of reasons for this. One is that there are many contexts in x86 in which various registers are used to hold addresses. Two important examples are the instruction pointer (EIP) and the stack pointer (ESP). With a 32-bit register on x86, virtual addresses can only be as high as (2^32)-1. That's 4 GiB. Another reason for the 32-bit virtual address limit is that 32 bits of virtual address are all that the address translation mechanism (page tables and all that) support. Same for the segment descriptors, though modern OSs don't use them much, they're still in the "address translation" path and can't be ignored.

On Windows this normally means that each process has up to 2 GiB v.a.s. for its code and data, and the OS has another 2 GiB for its code and data. Every process, though, gets another instance of that 2 GiB, so the total v.a.s. used on the system across all processes can be much higher than 4 GiB.

However, your question seems to be focused on RAM. If we're talking about x86, and if by "memory" the writer meant RAM, it means that the writer is unaware of developments that date back to 1995 (the Pentium Pro, which was the first to implement Physical Address Extension - PAE, and the forerunner of the Xeons).

More generally, it means they're unaware of how virtual memory works. They're assuming that RAM addresses are limited by the processor's general purpose registers, but that isn't the case once paging is enabled on the processor - which it always is on any modern OS. When paging is enabled, each address asserted by the running code is translated to a physical address via a set of tables called page tables. The maximum size of a physical address is therefore limited by the size of a ''page table entry'' rather than by the registers in the CPU.

In the original paging scheme implemented by Intel on ia32, physical addresses are limited to 32 bits just as virtual addresses are. However, if the OS puts the CPU into "PAE" mode, physical addresses can be anywhere from 36 to 52 bits wide (depending on processor family - it was 36 bits in the first PAE implementation, on the Pentium Pro and the first Xeons).

(This is not anything new. The industry history is filled with CPUs in which the physical address size is different from the machine's register width. The PDP-11, for example, is a 16-bit CPU, but supports up to 4 MB RAM. )

So, almost all modern "32-bit" x86 processors can address up to at least 64 GiB RAM (2^36 bytes).

Note however that the platform (the chipset and motherboard) has to cooperate in this - many motherboards have a RAM limit lower than what the CPU can support. Check your mobo manual or specs.

To use more than 4 GB RAM you also need an operating system that supports this. Windows 32-bit "client" editions, XP SP2 and later, do not - they are limited to 4 GB RAM. (A Windows "client" edition is anything that doesn't have "Server" in its name.) They are also limited to RAM addresses that fit in 32 bits.

But it's not specifically because the chip or the OS is 32 bits, it's because of an artificial limit compiled into Windows by Microsoft. They did this because they found that device drivers from some vendors, particularly those for video cards, caused crashes when used on machines with more than 4 GB RAM:

[...] the problematic client driver ecosystem led to the decision for [32-bit] client editions to ignore physical memory that resides above 4 GB, even though they can theoretically address it. — Russinovich, Solomon, and Ionescu: Windows Internals, 6th Edition, Part 2, section "Windows Client Memory Limits", page 321 (emph. added)

Note that there are 32-bit Windows Server editions that can use more than 4 GiB RAM. FAR more. So, 32-bit OS does NOT necessarily mean RAM is limited to 4 GiB (as is often claimed). The 4 GiB RAM limit on Windows client editions (actually it ends up at a little more than 3 GiB, if your I/O devices take up a lot of physical address space) is not an architectural limit. It's an artificial one, put into the system to protect it from poorly-written third-party device drivers.

What if I have 8GB RAM, does it mean it is more than necessary?

If your BIOS identifies that 8 GB RAM is present then some OSs will be able to use it all. But if you're running 32-bit Windows other than the higher-priced Server versions, then yes; the OS will not use more than 4 GB RAM. In that case you should install either Linux, or a 64-bit version of Windows, to make use of all of your RAM.

Related Question