Computer Science – 4.2 Assembly Language | e-Consult
4.2 Assembly Language (1 questions)
Login to see all questions.
Click on a question to view the answer
A two-pass assembler is a common type of assembler that performs the translation of assembly language instructions into machine code in two distinct passes. Each pass performs a specific set of operations, and the results of the first pass are used in the second pass. The stages are as follows:
- Pass 1: Symbol Table Generation
- The primary purpose of the first pass is to create a symbol table. This table stores information about the identifiers (labels) used in the assembly code, such as their memory addresses.
- The assembler reads the source code and identifies all the labels. It records the label and its corresponding memory address (or calculates it if the address is relative).
- The symbol table also stores information about constants defined in the assembly code.
- This pass does not produce any machine code; it only generates the symbol table.
- Pass 2: Code Generation
- The second pass uses the information from the symbol table generated in the first pass to translate the assembly code into machine code.
- The assembler reads the source code again. This time, it uses the symbol table to look up the addresses of labels.
- For each assembly instruction, the assembler determines the corresponding machine code operation. It then uses the symbol table to resolve any labels in the instruction to their actual memory addresses.
- The assembler generates the machine code instructions and writes them to an object file. The object file contains the machine code and any relocation information.
The symbol table is crucial for the assembler to correctly resolve labels and generate the correct machine code. Without the symbol table, the assembler would not know where to find the addresses of labels, and the generated machine code would be incorrect.