What Is Forward Referencing And Relocation Problem?


1 Answers

Amen Bukhari Profile
Amen Bukhari answered
Forward referencing is usually used in assembly language. In forward referencing variable or label is referenced before it is declared. Different problems can be solved using One Pass or Two Pass forward referencing. In One Pass forward referencing source program is translated instruction by instruction. Assembler leave address space for label when it is referenced and when assembler found the declaration of label, it uses back patching. Two Pass forward referencing consist of two passes.

During first pass symbol table, op-code table and label table are maintained. In op-code table instruction size and address is stored. Label and label's address is stored in label table. When label is encountered, its name is stored in label table when label declaration is found then its location is also stored in label table.

During 2nd Pass, translation from source language to machine language takes place. Instruction addresses and label addresses are used from symbol table instead of their names. Compiler does not know where program will be executed in the memory so complier generated logical addresses instead of absolute address. Loader also uses the Relocation Constant to solve the problem of relocation. External Referencing problem is resolves by the linker during compilation. Linder connects the object program to the code for standard library functions.

Answer Question