Skip to content

HillelZe/Assembly-Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assembly Language Interpreter

This is a project that interprets assembly language commands. The code is written in C.

The Logic

The core logic of this assembly language interpreter revolves around the struct "lineInfo". This struct is a representation of a line of assembly code, encompassing its label, operation, operands, syntax errors and other relevant data. By encapsulating all these details in a single data structure, we can simplify the process of interpreting and implementing each line of code.

When a file is read, each line of assembly code is converted into an instance of "lineInfo". This instance holds all the information needed to process the line further. The use of this struct allows for a clean and efficient way to manipulate assembly code lines during preprocessing, error checking, and final interpretation.

The preprocessing stage expands macros and deletes comments/empty lines, resulting in a new "after macro" file. We then start the first pass of the interpretation. For each raw text line of assembly code an instance of "lineInfo" is formed using the function analyzeLine. The "lineInfo" struct is then sent to implementLine which update each sort of information in the correct data structure: the symbol table, memory map, error list, extern/entry names, and the second pass table. The second pass table holds all the addresses that couldnt be filled during the first pass since their value depend on the symbol table. During the second pass we use the second pass table to go back to each of these addresses and fill them according to the completed symbol table.

In case errors were detectet during the interpretation of the code they will be printed with reference to the number of line in which the error occures in the after macro file. If the input code was valid an object code representing the memory map in base 64 will be created as well as entry and extern files.

This approach not only enhances the readability and maintainability of the code but also provides a logical and intuitive way to understand the flow of the assembly language interpreter.

Table of Contents

File Descriptions

The project is divided into several parts:

  • assembly.c: This is the main file that calls other functions to interpret assembly language code.

  • interpreter.c: This file is responsible for interpreting the assembly language code. It reads the code, breaks it into lines, and calls other functions to analyze and implement each line.

  • analyzeLine.c: This file contains functions that analyze a line of assembly code and create a "lineInfo" struct that holds all the relevant information.

  • implementLine.c: This file contains functions that takes a "lineInfo" struct and extract the its information into the relevant data structures.

  • symbolList.c: This file manages a linked list of labels used in the assembly code. It provides functions for adding a new label, printing the list of labels, freeing the memory allocated to the list, and searching for a label in the list.

  • preprocess.c: This file contains functions for preprocessing the assembly code. It can parse and expand macros in the code.

  • errorList.c: This file manages a list of errors encountered during the interpretation of the assembly code. It provides functions for adding a new error to the list, printing the list of errors and freeing the memory.

  • 'createOb.c': This file contain a function that gets the memory map and convert it into a base64 object file.

Usage

To run the interpreter on a file named input.am, use the following command:

./assembly input.am

Lessons Learned

Working on this assembly language interpreter project was a significant learning experience in various aspects. It provided a deeper understanding of how high-level languages interface with lower-level hardware instructions, reinforcing the concepts of assembly language and its role in computer systems.

We learned how to effectively design and implement data structures, like the "lineInfo" struct, to encapsulate complex data and simplify the codebase. This practice enhanced the readability and maintainability of the code, leading to more efficient development and debugging processes.

Working with file I/O operations in C and dealing with errors also strengthened our skills in robust and resilient programming. We faced challenges in handling edge cases and errors, which taught us the importance of comprehensive error checking in software development.

The project also emphasized the significance of good software architecture, specifically modular design. By separating the code into distinct modules, we could work on different parts of the interpreter independently, improving the project's overall manageability.

Finally, this project underscored the power of macros in simplifying code and making it more flexible and reusable. It was an exercise in understanding and implementing preprocessor directives, which are often overlooked but can be immensely powerful tools in a programmer's toolkit.

👥 Authors

This project was developed in collaboration by:

  • Hillel Zehavi
  • Gal Sapir

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors