Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Phases of a Assembler
Next article icon

Phases of a Assembler

Last Updated : 17 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
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.


Next Article
Phases of a Assembler

R

rathodavinash1181
Improve
Article Tags :
  • Technical Scripter
  • Compiler Design
  • Technical Scripter 2022

Similar Reads

    Phases of a Compiler
    A compiler is a software tool that converts high-level programming code into machine code that a computer can understand and execute. It acts as a bridge between human-readable code and machine-level instructions, enabling efficient program execution. The process of compilation is divided into six p
    10 min read
    Difference Between Assembler and Interpreter
    Humans can only understand source codes written in high-level languages like Python, java, c++, etc, or low-level languages like PHP. On the other hand, computers can only understand machine code written in 0s and 1s. To solve this issue we need a translator that can translate the source code into m
    4 min read
    Grouping of Phases in Compiler Design
    A compiler is software that translates a high-level language into machine-understandable form. Typically, a compiler is made up of six states and the input code in high-level language also known as Source code passes through each state one by one, each state processes the code, resulting in machine-
    5 min read
    Advantages and Disadvantages of Assembler
    Pre-requisites: Introduction of AssemblerLanguage Processors: Assembler, Compiler, and InterpreterAn assembler is a software program that translates assembly language code into machine code. Assembly language is a low-level programming language that is specific to a particular computer architecture,
    6 min read
    Difference between Compiler and Assembler
    A compiler and an assembler are significant resources required for the conversion of high-level and low-level programming languages into forms that are understandable to the machine. While they are both used in today’s programming and provide roughly the same services, they are written in two differ
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences