Memory partitions

Relocation

This stems from the problem that when the program is compiled, the compiler does not know where the program will be placed in memory. While it would in principle be possible for the program to be compiled in such a way that it could be relocated, this can be awkward and inefficient. What is needed is a way to get from the addresses generated by the compiler (which assume that the program has been loaded at address 0, say)---the logical (or virtual addresses), to the physical addresses corresponding to where the program has actually been loaded in memory.

It makes sense to compile programs to begin at location 0 in (virtual) memory, so this is what is shown in the diagram to the left. The program is 20416 bytes in length. It is relocated to memory location 64E016.

In this example, say there is a subroutine to be called at location 11B16 in the program. All references to this subroutine must be relocated, to refer to location (64E016 + 11B16) = 65FB16.

software solution

when the program is loaded, its addresses are adjusted by the OS loader. Simple solution. Has disadvantage that the process may not later be easily moved. In practice, exe file contains list of all the absolute addresses in the program. The loaded goes in there and uses this list to patch up the executable code.

hardware solution

a 'base register' in CPU is automatically added to every memory address. This way the addresses are not changed until the memory access is actually made. It has the advantage that processes may be easily relocated. Only the code need be moved; it need not be modified.


last updated 3 March 1998