ADDRESS REFERENCE ADJUSTMENT UPON CODE RELOCATION Relocation of programs generally calls for a few internal adjustments. Parts of a program (certain of its instructions) typically reference addresses within the program. Obviously, if the program as a whole gets shifted from one place in memory to another (i.e., relocated), every portion of the program moves with it. So any part of the program that accounts for the address of the program, must account for the change of address of the program. This is discussed in the Stallings textbook's chapter 7 and specifically Appendix 7A. Here is an example. It is a machine language program whose load point is at memory location 500. Suppose it is reloaded at 850 instead, shown in the middle column. Then the operands of the 4 instructions have to change, because they reference the data portion of the program and it has moved. In general, if the program is relocated to an address x, the needed adjustments in terms of x are shown in the rightmost column. Initial memory: If relocated to 850: If relocated to x: 500 1 505 850 1 855 x 1[x+5] 501 3 506 851 3 856 x+1 3[x+6] 502 5 507 852 5 857 x+2 5[x+7] 503 2 504 853 2 854 x+3 2[x+4] 504 0007 854 0007 x+4 0007 505 0008 855 0008 x+5 0008 506 0002 856 0002 x+6 0002 507 0003 857 0003 x+7 0003