Program Relocation
Program Relocation
The need for program relocation It is desirable to load and run several programs at the same time. The system must be able to load programs into memory wherever there is room. The exact starting address of the program is not known until load time. Absolute Program Program with starting address specified at assembly time The address may be invalid if the program is loaded into somewhere else. Example:
The only parts of the program that require modification at load time are those that specify direct addresses. The rest of the instructions need not be modified. Not a memory address (immediate addressing) PC-relative, Base-relative From the object program, it is not possible to distinguish the address and constant.
The assembler must keep some information to tell the loader. The object program that contains the modification record is called a Relocatable Program. The way to solve the relocation problem For an address label, its address is assigned relative to the start of the program(START 0) Produce a Modification record to store the starting location and the length of the Address field to be modified. The command for the loader must also be a part of the object program. Modification record One modification record for each address to be modified The length is stored in half-bytes (4 bits) The starting location is the location of the byte containing the leftmost bits of the address field to be modified. If the field contains an odd number of half-bytes, the starting location begins in the middle of the first byte.