This project implements an assembler in C for a custom assembly language.
The assembler receives .as source files, expands macros, performs a first pass and a second pass, and generates the required output files according to the project specifications.
To compile the project, run:
makeTo clean compiled files:
make cleanRun the assembler with one or more file names, without the .as extension:
./assembler psMultiple files are supported:
./assembler file1 file2 file3For example, running:
./assembler pswill process the file:
ps.as
The assembler may generate the following files:
.am– source file after macro expansion..ob– object file containing the encoded machine words..ent– entry symbols file, created only when valid.entrysymbols exist..ext– external symbol references file, created only when external symbols are actually used.
If errors are detected, the assembler prints the relevant error messages and does not generate the final output files.
main.c– runs the assembler flow for each input file.pre_assem.c/pre_assem.h– handles macro expansion and creates the.amfile.first_pass.c/first_pass.h– performs the first pass, builds the symbol table, and calculates instruction and data addresses.second_pass.c/second_pass.h– performs the second pass, resolves symbols, handles entries and externals, and creates output files.instruction_utils.c/instruction_utils.h– handles instruction parsing, addressing modes, opcode encoding, and operand encoding.data_utils.c/data_utils.h– handles data directives such as.data,.string, and.mat.symbol_table.c/symbol_table.h– manages the symbol table.file_io.c/file_io.h– handles file operations and output file writing.mcros.c/mcros.h– manages macro storage and lookup.utils.c/utils.h– general helper functions.makefile– builds the project.
The assembler supports the following directives:
.data.string.mat.entry.extern
- Macro definition and expansion.
- Two-pass assembly process.
- Symbol table management.
- Instruction encoding.
- Multiple addressing modes:
- Immediate addressing
- Direct addressing
- Matrix/index addressing
- Register addressing
- Entry and external symbol handling.
- Error reporting with line numbers.
- Support for multiple input files in one run.
The assembler reports errors such as:
- Undefined
.entrysymbols. - Undefined symbols.
- Invalid symbols.
- Invalid addressing modes.
- Lines longer than the allowed maximum length.
- Macro definition errors.
- File opening or writing errors.
If errors are found, the assembler prints the errors and does not generate the final output files.
- The project is written in ANSI C / C90 style.
- The project is compiled using strict flags such as:
-ansi -Wall -pedantic- Debug prints were removed from the final version so that only required error messages are displayed.