Computer Science – 4.2 Assembly Language | e-Consult
4.2 Assembly Language (1 questions)
The symbol table is a fundamental data structure in a two-pass assembler. It acts as a central repository of information about the identifiers (labels) used in the assembly source code. It's essential for the assembler to correctly translate assembly instructions into machine code.
The symbol table typically stores the following information for each identifier:
- Symbol Name (Label): The name of the label as it appears in the assembly code.
- Address: The memory address associated with the label. This could be a direct address or a relative address.
- Size: The size of the symbol (e.g., byte, word, doubleword). This is important for correctly interpreting instructions that operate on symbols of different sizes.
- Type: The type of the symbol (e.g., data, code, constant).
During Pass 1 (Symbol Table Generation): The assembler reads the source code and creates an entry in the symbol table for each unique label. It records the label's name and its corresponding memory address (or calculates it). It also records constants and their values.
During Pass 2 (Code Generation): The assembler uses the symbol table to resolve labels in the assembly code. When the assembler encounters a label in an instruction, it looks up the label's address in the symbol table. This address is then used to generate the correct machine code instruction. The symbol table also helps in handling relative addressing modes, as it provides the base address needed for calculating the effective address.
Without the symbol table, the assembler would not be able to determine the location of labels, and the generated machine code would be incorrect. The symbol table is therefore a critical component of the two-pass assembler.