Open In App

Phases of a Assembler

Last Updated : 17 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Assembler is a program that converts assembly language into machine language that can be executed by a computer. The Assembler operates in two main phases: Analysis Phase and Synthesis Phase. The Analysis Phase validates the syntax of the code, checks for errors, and creates a symbol table. The Synthesis Phase converts the assembly language instructions into machine code, using the information from the Analysis Phase. These two phases work together to produce the final machine code that can be executed by the computer. The combination of these two phases makes the Assembler an essential tool for transforming assembly language into machine code, ensuring high-quality and error-free software.

1) Analysis Phase 

  1. The primary function performed by the analysis phase is the building of the symbol table. It must determine the memory address with which each symbolic name used in a program is associated in the assembly program of the address of  N would be known only after fixing the addresses of all program elements-whether instructions or memory areas-that preceding it. This function is called memory allocation.
  2. Memory allocation is performed by using a data structure called location counter (LC). 
  3. The analysis phase ensures that the location counter always contains  the address that the next memory word in the target program should have
  4. At the start of its processing, it initializes the location counter to the constant specified in the START statement. 
  5. While processing a statement, it checks whether the statement has a label. 
  6.  If so, it enters the label and the address contained in the location counter in a new entry of the symbol table. It then finds how many memory words are needed for the instruction or data represented by the assembly statement and updates the address in the location counter by that number. (Hence the word ‘counter’ in location counter”.).
  7. The amount of memory needed for each assembly statement depends on the mnemonic of an assembly statement. It obtains this information from the length field in the mnemonics table. 
  8. It obtains this information from the length field in the mnemonics table. For DC and DS statements, the memory requirement further depends on the constant appearing in the operand field, so the analysis phase should determine it appropriately.
  9. We use the notation <LC> for the address contained in the location counter.
  10. The Symbol table is constructed during analysis and used during synthesis. 

 

The Mnemonics table is a fixed table that is merely accessed by the analysis synthesis phases (see the arrows depicting data access). 
The tasks performed by the analysis and synthesis phases can be summarized. 
followed as 

Analysis phase:

  • Separate contents of the label, mnemonic opcode and operand fields of a statement. 
  • If a symbol is present in the label field, enter the pair (symbol, <LC>) in a new entry of the symbol table. 
  • Check validity of the mnemonic opcode through a look-up in the Mnemonics table. 
  • Perform LC processing, i.e., update the address contained in the location counter by considering the opcode and operands of the statement. 

Synthesis phase:

  •  Obtain the machine opcode corresponding to the mnemonic from the Mnemonics table. 
  •  Obtain the address of each memory operand from the Symbol table.
  • Synthesize a machine instruction or the correct representation of a constant, as the case may be. 

Significance of Both Phases in Assembler

The Analysis Phase and Synthesis Phase are both essential components of the Assembler. The Analysis Phase breaks down the assembly language code into its constituent parts, such as symbols, labels, and instructions. This phase is responsible for validating the syntax of the code, checking for errors, and creating a symbol table that maps symbols to memory addresses. This phase is crucial for ensuring the code is error-free and well-formed, which helps to prevent issues during the execution of the program.

The Synthesis Phase is responsible for converting the assembly language instructions into machine code that can be executed by the computer. This phase uses the information from the Analysis Phase, such as the symbol table, to create the machine code and generate a listing file that shows the machine code and memory addresses for each instruction. The Synthesis Phase is critical for producing the final machine code that can be executed by the computer, making it the final step in the process of transforming assembly language code into machine code.

In conclusion, both the Analysis Phase and Synthesis Phase play a vital role in the Assembler. The Analysis Phase ensures the code is error-free and well-formed, while the Synthesis Phase produces the final machine code that can be executed by the computer. The combination of these two phases makes the Assembler an essential tool for converting assembly language code into machine code, which is critical for producing high-quality and error-free software.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads