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