This is a 12-bit assembler for the System Programming Laboratory course (20465) at the Open University of Israel.
It is written in ANSI C (C89), follows a modular layout, and transforms .as sources into preprocessed .am files and Base64-encoded object output.
| Topic | Description |
|---|---|
| Project Type | 12-bit assembler with deferred symbol resolution |
| Academic Context | System Programming Laboratory (Open University) |
| Language | ANSI C (C89) |
| Input / Output | .as files -> .am, .ob (Base64), .ent, .ext |
| Directory | Responsibility |
|---|---|
Assembler/ |
Orchestrates compilation, symbol handling, and backpatching. |
Lexical_analysis/ |
Parses lines and classifies commands, directives, and operands. |
preprocessor/ |
Handles macro expansion and writes the .am stage. |
Output_files/ |
Generates .ob, .ent, and .ext files. |
Data_structures/ |
Infrastructure for fast Trie lookups and dynamic Vector storage. |
The assembler operates in a modular pipeline: source files are expanded via the preprocessor, analyzed for lexical patterns, and then processed by the core logic to resolve labels and generate encoded machine words.
flowchart LR
A[.as source] --> B[preprocessor]
B --> C[.am file]
C --> D[Lexical_analysis]
D --> E[Assembler core]
E --> F[Output_files]
G[Trie + Vector] -. support .-> B
G -. support .-> D
G -. support .-> E
git clone https://github.com/guyGojanski/C_Assembler.gitcd C_AssemblerIntall WSL from PowerShell as Administrator:
wsl --installComplete the Ubuntu setup by creating a username and password.
Inside your WSL terminal, install the required tools:
sudo apt update && sudo apt install build-essentialUnlike traditional two-pass designs, this assembler completes translation in one main scan of the .am file.
- Scan stage: the assembler scans each line. Known symbols are emitted immediately. If an undefined label is encountered, a placeholder word is inserted.
- Deferred fixups: a direct pointer to the placeholder's memory location is stored. Once the scan ends, the assembler backpatches these addresses directly in memory.
- Relocation: data symbols are relocated once the final code size is known.
-
Trie: character-driven lookup providing$O(L)$ efficiency for reserved keywords and labels. -
Vector: dynamic containers that avoid fixed-size limits and provide direct pointers for efficient backpatching.
makeThe project uses strict compiler flags:
-Wall-ansi-pedantic
./assembler_program test/ok/ok1test/
├── error/ # Intentional syntax and logic errors.
├── ok/ # Valid assembly cases for Base64 verification.
└── warning/ # Diagnostic warnings for non-critical issues.
./assembler_program test/ok/ok1 test/ok/ok2 test/ok/ok3
./assembler_program test/error/error
./assembler_program test/warning/warning1 test/warning/warning2This README summarizes the project workflow, structure, build steps, and testing layout. The code is intentionally modular so each stage can be understood and maintained independently.