A complete two-pass assembler built in ANSI C, designed to translate assembly code for a custom CPU architecture.
This project was developed as part of the *System Programming Lab * course at the University.
The assembler reads .as source files, performs two passes over the code, expands macros, builds symbol tables, resolves labels, and generates machine-level output files:
.obβ object code.entβ entries.extβ external references
It supports all standard directives (.data, .string, .struct, .extern, .entry) and implements strong validation and error handling for both passes.
- Two-Pass Compilation:
First pass builds symbol tables and detects syntax errors.
Second pass encodes instructions and resolves references. - Macro Preprocessor:
Expands user-defined macros before assembly (.amfiles). - Symbol & Label Management:
Handles.entryand.externdirectives with relocation support. - Machine Code Generation:
Outputs 10-bit word binary code to.ob,.ent, and.extfiles. - Error Handling:
Detects invalid labels, directives, addressing modes, and memory references. - Modular Design:
Split into modules β lexer, parser, code generator, and utilities.
assembler/
βββ main.c
βββ preprocessor.c
βββ parser.c
βββ assembler.c
βββ codegen.c
βββ utils.c
βββ include/
β βββ assembler.h
β βββ globals.h
βββ Makefile
make
./assembler file1.as file2.asInput:
MAIN: mov r3, LENGTH
LOOP: jmp ENDOutput files:
file.ob
file.ent
file.ext
C (ANSI), Makefile, File I/O, Custom ISA, Macro Preprocessor, Data Structures
System Programming Lab