Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Two Pass Builder - SIC/SIC-XE Assembler

A two-pass assembler implementation for SIC (Simplified Instructional Computer) and SIC-XE (SIC with eXtra Equipment) architectures, written in Rust.

Overview

This project implements a complete two-pass assembler that translates SIC and SIC-XE assembly language programs into executable machine code. The assembler follows the traditional two-pass approach:

  • Pass 1: Builds the symbol table and calculates memory addresses
  • Pass 2: Generates object code and creates the executable file

Features

  • ✅ Complete SIC instruction set support
  • ✅ SIC-XE extended instruction set support
  • ✅ Format 1, 2, 3, and 4 instruction handling
  • ✅ Extended format instructions (+ prefix)
  • ✅ Addressing modes: direct, indirect (@), immediate (#), indexed (,X)
  • ✅ PC-relative and base-relative addressing
  • ✅ Symbol table generation
  • ✅ Object program generation with header, text, modification, and end records
  • ✅ Error detection and reporting

Project Structure

two_pass_builder/
├── src/
│   ├── main.rs          # Main program entry point
│   ├── pass_one.rs      # First pass implementation
│   ├── pass_two.rs      # Second pass implementation
│   └── read.rs          # File reading utilities
├── examples/
│   ├── sic.asm          # Sample SIC assembly program
│   ├── sicxe.asm        # Sample SIC-XE assembly program
│   ├── sic.result       # Expected output for SIC
│   └── sicxe.result     # Expected output for SIC-XE
├── pass1/               # Output directory for Pass 1
├── pass2/               # Output directory for Pass 2
├── OBTAB.json           # Operation code table
└── Cargo.toml           # Rust project configuration

Dependencies

  • serde - For JSON serialization/deserialization
  • serde_json - For JSON handling

Installation

  1. Ensure you have Rust installed on your system
  2. Clone this repository
  3. Navigate to the project directory
  4. Build the project:
    cargo build --release

Usage

Running the Assembler

cargo run

The assembler will process the default input file examples/sic.asm and generate:

Pass 1 Output (in pass1/ directory):

  • processed.masm - Processed assembly with location counters
  • SYMTAB.json - Symbol table in JSON format
  • general_info.json - Program metadata (length, starting address)

Pass 2 Output (in pass2/ directory):

  • output.executable - Final object program

Input Format

Assembly programs should follow SIC/SIC-XE syntax:

COPY      START     1000      COPY FILE FROM INPUT TO OUTPUT
FIRST     STL       RETADR    SAVE RETURN ADDRESS
CLOOP     JSUB      RDREC     READ INPUT RECORD
          LDA       LENGTH    TEST FOR EOF (LENGTH = 0)
          COMP      ZERO
          JEQ       ENDFIL    EXIT IF EOF FOUND
          END       FIRST

Supported Instructions

The assembler supports all standard SIC and SIC-XE instructions as defined in OBTAB.json, including:

Load/Store Instructions:

  • LDA, LDB, LDL, LDS, LDT, LDX, LDCH
  • STA, STB, STL, STS, STT, STX, STCH

Arithmetic Instructions:

  • ADD, SUB, MUL, DIV
  • ADDF, SUBF, MULF, DIVF (floating point)
  • ADDR, SUBR, MULR, DIVR (register-to-register)

Control Instructions:

  • J, JEQ, JGT, JLT, JSUB, RSUB
  • COMP, COMPF, COMPR

I/O Instructions:

  • RD, WD, TD

Assembler Directives:

  • START - Define program starting address
  • END - End of program
  • BYTE - Define byte constant
  • WORD - Define word constant
  • RESB - Reserve bytes
  • RESW - Reserve words
  • BASE - Set base register

Addressing Modes

SIC Addressing:

  • Direct: LDA ALPHA
  • Indexed: LDA ALPHA,X

SIC-XE Addressing:

  • Direct: LDA ALPHA
  • Indirect: LDA @ALPHA
  • Immediate: LDA #100
  • Indexed: LDA ALPHA,X
  • Extended: +LDA ALPHA

Architecture Support

SIC (Simplified Instructional Computer)

  • 15-bit addresses
  • 6 registers (A, X, L, B, S, T)
  • Format 3 instructions (3 bytes)

SIC-XE (SIC with eXtra Equipment)

  • 20-bit addresses
  • 9 registers (A, X, L, B, S, T, F, PC, SW)
  • Format 1 (1 byte), Format 2 (2 bytes), Format 3 (3 bytes), Format 4 (4 bytes)
  • PC-relative and base-relative addressing

Object Program Format

The assembler generates object programs in standard format:

  • Header Record (H): Program name, starting address, and length
  • Text Records (T): Object code grouped into records
  • Modification Records (M): Addresses requiring relocation (SIC-XE only)
  • End Record (E): End of object program with execution start address

Error Handling

The assembler detects and reports various errors:

  • Undefined symbols
  • Duplicate symbol definitions
  • Invalid instruction formats
  • Addressing mode violations
  • Invalid operands

Example

Input (sic.asm):

COPY      START     1000
FIRST     STL       RETADR
          LDA       LENGTH
          COMP      ZERO
          JEQ       ENDFIL
ENDFIL    LDA       EOF
          END       FIRST

Output (object program):

H^COPY  ^001000^00001E
T^001000^0E^141033^001030^281030^301015^001033
E^001000

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is open source. See the repository for license details.

References

  • System Software: An Introduction to Systems Programming by Leland L. Beck
  • SIC and SIC-XE Architecture Specifications

About

SICXE two pass assembler

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages