Consider the following CPU instruction, which takes memory at 16777386 (decimal) and stores it in register 1:
Move &0x010000AA, R1
Traditionally, programs are translated into assembly (machine code) at compile time. (Let them ignore more complex modern systems, such as jitting).
However, if this address allocation is statically static at compile time, how does the OS ensure that two processes do not use the same memory? (for example, if you simultaneously ran the same compiled program at the same time).
Question:
How and when does the program receive the memory addresses assigned to it?
Virtual memory:
I understand that most (if not all) modern systems use memory management modules in hardware that allow the use of virtual memory. The first few octets of the address space are used to link to the page. This will protect memory if each process uses different pages. However, if so, how is memory protection ensured, is the original question still persisting, only this time with how page numbers are assigned?
EDIT
CPU:
One possibility is that the processor can handle memory protection by applying a process identifier to the OS before executing memory-based instructions. However, this is only an assumption and requires hardware support for the processor architecture, which I'm not sure that the RISC ISAs will be developed.