Skip to content

Two-pass assembler written in ANSI C for a fictional CPU architecture. Implements macro preprocessing, symbol tables, and machine code generation.

Notifications You must be signed in to change notification settings

SEDENYS/assembler-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 Two-Pass Assembler in C

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.


🚀 Overview

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.


⚙️ Features

  • 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 (.am files).
  • Symbol & Label Management:
    Handles .entry and .extern directives with relocation support.
  • Machine Code Generation:
    Outputs 10-bit word binary code to .ob, .ent, and .ext files.
  • Error Handling:
    Detects invalid labels, directives, addressing modes, and memory references.
  • Modular Design:
    Split into modules — lexer, parser, code generator, and utilities.

🧱 Project Structure

assembler/
│── main.c
│── preprocessor.c
│── parser.c
│── assembler.c
│── codegen.c
│── utils.c
│── include/
│   ├── assembler.h
│   ├── globals.h
│── Makefile

🧩 Example Usage

make
./assembler file1.as file2.as

Input:

MAIN: mov r3, LENGTH
LOOP: jmp END

Output files:

file.ob
file.ent
file.ext

🧠 Tech Stack

C (ANSI), Makefile, File I/O, Custom ISA, Macro Preprocessor, Data Structures


📜 License

System Programming Lab

About

Two-pass assembler written in ANSI C for a fictional CPU architecture. Implements macro preprocessing, symbol tables, and machine code generation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages