问题
Until now I thought that a 32-bit processor can use 4 GiB of memory because 232 is 4 GiB, but this approach means processor have word size = 1 byte. So a process with 32-bit program counter can address 232 different memory words and hence we have 4 GiB.
But if a processor has word size larger than 1 byte, which is the case with most of processors now days I believe (My understanding is that word size is equal to the width of data bus, so a processor with 64-bit data bus must have a word size = 8 bytes).
Now same processor with 32 bit Program counter can address 2^32 different memory words, but in this case word size is 8 bytes hence it can address more memory which contradicts with 4 GiB thing, so what is wrong in my argument ?
回答1:
CPU (at least x86 family 32-bit) must be able to access any byte/word/dword in 4GB space. So an instruction is encoded such a way that target word size and memory address (usually) belong to different bit-fields. So it doesn't matter whether CPU accesses byte or dword, but the encoded memory address must be the same.
Note that 32-bit OS and x86 CPU technically is able to acccess more than 4GB address space using PAE mode. But it is not supported by, say, the current Windows OS family (except Server editions). Some versions of WinXP, as well as Linux and other 32-bit OS can address 64GB of memory on x86 CPU.
Also, usually OS reserves some part of virtual address space (for OS kernel, Video memory etc.), so user programs may use, say, no more than 3 GB of RAM of the 4GB an OS can address within each process.
回答2:
Your premise is incorrect. 32-bit architectures can address more than 4GB of memory, just like most 8-bit microcontrollers can use more than 256 bytes of memory.
For example 64-bit JVM can address 32GB of memory with 32-bit pointer using compressed Oops. See the Trick behind JVM's compressed Oops
32-bit x86 CPUs can also address 64GB of memory with PAE. The analog on ARM is LPAE.
The main thing here is that a 32-bit process only has 4GB of address, so it can't address more even though the OS itself supports more than 4GB of RAM. Generally the address space is split between user and kernel space, hence limited the user memory even more. There are several ways to workaround this
- Spawning multiple processes, which is used in Adobe Premiere CS4
- Mapping the needed part of memory into the current address space, like Address Windowing Extensions on Windows
- ...
You're still correct that a 32-bit program counter can address 232 different memory words. But no modern architectures use word-addressable memory although they did exist in the past
来源:https://stackoverflow.com/questions/33582419/why-32-bit-processor-can-only-address-4gib-of-memory-even-with-large-word-size