Developed by: AmirHossein Karimi & Moein Hosseini 🤝🔥
Welcome! This repository contains a small educational two-pass assembler implemented in C.
- Overview
- Files
- Build & Run (CLion / CMake)
- Build & Run (Command-line / MinGW / GCC)
- Examples
- Troubleshooting
- Quick checklist
This assembler performs a two-pass assembly on a small instruction set and supports directives .SPACE and .FILL.
- Input: plain-text
.asmfile - Output: text
.mcmachine code file (one integer per line) - Pass 1: build symbol table
- Pass 2: generate machine code
Supported mnemonics include: ADD, SUB, SLT, OR, NAND, ADDI, ORI, SLTI, LUI, LW, SW, BEQ, JALR, J, HALT.
Key files and folders:
Final/assembler.h— public header (types & prototypes)main.c— program entrypoint (arg parsing, defaults)parser.c— parsing & assembly logic (pass1 + pass2)symbol_table.c— symbol table functionsprogram.asm— sample assembly (recommended test file)Makefile.txt— example Makefile for quick gcc builds
main.c— legacy monolithic assembler (alternate)CMakeLists.txt— project CMake file (buildsFinal/sources)cmake-build-debug/Assembler.exe— built executable (CLion debug)explanation.pdf,Final Phase 1.pdf— documentation
If you don’t want to build from source, you can download a ready-to-use ZIP from the Releases page.
- Open the repository on GitHub.
- Click Releases (right side panel or top section).
- Open the latest release.
- Under Assets, download the ZIP file (for example:
Assembler-windows.zip).
- Right-click the ZIP file and choose Extract All...
- Open the extracted folder.
- If the release includes
Assembler.exe, open PowerShell inside that folder and run:
.\Assembler.exe program.asm output.mc- Or double-click
Assembler.exe(if your package is prepared for double-click run).
program.asm= input assembly fileoutput.mc= output machine code file- You can replace filenames with your own files:
.\Assembler.exe my_input.asm my_output.mc- Click More info → Run anyway (only if you trust the file/source).
Recommended: open the repository in CLion and run the Assembler CMake target.
- Open the repository root in CLion.
- Let CLion load the
CMakeLists.txt(or choose "Reload CMake Project"). - Build via Build → Build Project.
Or from PowerShell:
cd "E:\Amir\git hub repository work\Assembler"
cmake -S . -B build
cmake --build build --config DebugRun (example):
.\cmake-build-debug\Assembler.exe Final\program.asm output.mcNotes:
- In CLion, run the CMake target
Assembler(not a single source file). Running a single.cfile may compile only that file and cause linker errors (undefined references to symbols defined in other source files). - Set the Run Configuration working directory to the project root to use default
Final/program.asmwhen no args are passed.
Option A — CMake (recommended):
cd "E:\Amir\git hub repository work\Assembler"
cmake -S . -B build -G "MinGW Makefiles"
cmake --build build --config Release
build\Assembler.exe Final\program.asm output.mcOption B — Direct gcc (quick test):
cd Final
gcc -o assemble main.c parser.c symbol_table.c -std=c17 -Wall
.\assemble program.asm output.mcOption C — Example Makefile in Final/:
cd Final
make -f Makefile.txt
.\assemble Final\program.asm output.mc- Run with defaults (no args):
Final/main.cwill useprogram.asmand writeoutput.mcin the current working directory — make sure the input file is present or pass full paths.
-
Linker errors (undefined reference to
init_symbol_table,open_and_read_file_Pass1, etc.):- Cause: compiling/running only
main.c(single-file run) so the linker doesn't includeparser.candsymbol_table.c. - Fix: build/run the full CMake target (Assembler) so CLion or your build links all sources listed in
CMakeLists.txt.
- Cause: compiling/running only
-
"Executable not found" after build:
- Verify the build output directory (
cmake-build-debug\orbuild\). CLion typically places the exe undercmake-build-debug\.
- Verify the build output directory (
-
Assembler errors (undefined label / out-of-range immediate):
- Inspect your
.asmfile for misspelled labels, incorrect directives, or immediates outside allowed ranges. Use.FILLand.SPACEcorrectly.
- Inspect your
- Use
Final/modular sources and the CMake targetAssembler. - For quick tests compile
Final/main.c,Final/parser.c, andFinal/symbol_table.ctogether. - If you see linker undefined references in CLion, stop running the single file: run the CMake .
Made with ❤️ by Amir & Moein
🔗 Check us out on GitHub: