Assembler Functions and Two-Phase Translation

Classified in Computers

Written at on English with a size of 2.83 KB.

Functions of an Assembler

The fundamental task of an assembler is to translate a program in assembly language to code for machine language. In essence, the assembler must perform the following tasks:

  • Convert the code (opcode or mnemonic: e.g., LDA, STX) to the equivalent code in machine language.
  • Convert symbolic operands (tags or variables) into the addresses of the operands.
  • Build the machine language instructions in the appropriate format.
  • Convert the constants defined in the program into their true representation.
  • Write the "listing" in assembly language to machine language code.
  • Process the assembly guidelines. The guidelines are instructions or commands directed to the assembler, which it processes and executes as it encounters them in the assembly language program. These guidelines are not translated into machine language. Instead, the assembler performs an action, such as allocating memory for variables, etc.

In general, most tasks can be performed if the program is traversed line by line. However, a difficulty arises when translating an operating instruction that is defined later in the program. If this happens, the assembler does not know the address of the operand, and the instruction cannot be assembled.

One-Phase Assemblers

These assemblers read a source program line and translate it directly to produce a machine-language instruction or execute a pseudoinstruction. They also build the symbol table as variable definitions, labels, etc., appear.

Because of their translation method, these assemblers require symbols to be defined before they are used. This ensures that when a reference to a particular symbol is encountered in an instruction, the assembler knows the address of that symbol and can translate it correctly. These assemblers are simple, inexpensive, and take up little space, but they have the aforementioned drawback.

Two-Phase Assemblers

Two-phase assemblers are named so because they perform the translation in two stages. In the first phase, they read the source program and build a symbol table. In this way, during the second phase, they re-read the source program and can fully translate it since they know all the symbols.

Entradas relacionadas: