Your JavaScript is Disabled, Please Enable

2 - Pass Assembler


      2 - Pass Assembler is the mini project in Rajiv Gandhi Institute of Technology for the subject of System Programming and Compiler Construction(2012). Assembler was developed using JAVA with the program input comes from file and output eventually written to the file as a tables.An assembler is a translator, that translates an assembler program into a conventional machine language program. Basically, the assembler goes through the program one line at a time, and generates machine code for that instruction. Then the assembler proceeds to the next instruction. In this way, the entire machine code program is created. For most instructions this process works fine, for example for instructions that only reference registers, the assembler can compute the machine code easily, since the assembler knows where the registers are.

Consider an assembler instruction like the following
JMP LATER
...
...
LATER:

      This is known as a forward reference. If the assembler is processing the file one line at a time, then it doesn't know where LATER is when it first encounters the jump instruction. So, it doesn't know if the jump is a short jump, a near jump or a far jump. There is a large difference amongst these instructions. They are 2, 3, and 5 bytes long respectively. The assembler would have to guess how far away the instruction is in order to generate the correct instruction. If the assembler guesses wrong, then the addresses for all other labels later in the program would be wrong.

      Solution to this Problem is 2 - Pass Assembler. In first pass, just count how long the machine code instructions will be, just to find out the addresses of all the labels. Also, create a table that has a list of all the addresses and where they will be in the program. This table is known as the symbol table. On the second Pass, generate the machine code, and use the symbol table to determine how far away jump labels are, and to generate the most efficient instruction.