in Compiler Design edited by
1,378 views
0 votes
0 votes

In two pass assembler the symbol table is used to store :

  1. Label and value
  2. Only value
  3. Mnemonic
  4. Memory Location
in Compiler Design edited by
1.4k views

1 Answer

1 vote
1 vote

First Pass

On the first pass, the assembler performs the following tasks:

  • Checks to see if the instructions are legal in the current assembly mode.
  • Allocates space for instructions and storage areas you request.
  • Fills in the values of constants, where possible.
  • Builds a symbol table, also called a cross-reference table, and makes an entry in this table for every symbol it encounters in the label field of a statement.

symbol table:-

The assembler reads one line of the source file at a time. If this source statement has a valid symbol in the label field, the assembler ensures that the symbol has not already been used as a label. If this is the first time the symbol has been used as a label, the assembler adds the label to the symbol table and assigns the value of the current location counter to the symbol. If the symbol has already been used as a label, the assembler returns the error message Redefinition of symbol and reassigns the symbol value.

The assembler keeps scanning statements and building its symbol table until there are no more statements to read.

At the end of the first pass, all the necessary space has been allocated and each symbol defined in the program has been associated with a location counter value in the symbol table. When there are no more source statements to read, the second pass starts at the beginning of the program.

Second Pass

On the second pass, the assembler:

  • Examines the operands for symbolic references to storage locations and resolves these symbolic references using information in the symbol table.
  • Ensures that no instructions contain an invalid instruction form.
  • Translates source statements into machine code and constants, thus filling the allocated space with object code.
  • Produces a file containing error messages, if any have occurred.

Related questions