A two-pass assembler implementation for SIC (Simplified Instructional Computer) and SIC-XE (SIC with eXtra Equipment) architectures, written in Rust.
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
- ✅ 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
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
serde- For JSON serialization/deserializationserde_json- For JSON handling
- Ensure you have Rust installed on your system
- Clone this repository
- Navigate to the project directory
- Build the project:
cargo build --release
cargo runThe assembler will process the default input file examples/sic.asm and generate:
Pass 1 Output (in pass1/ directory):
processed.masm- Processed assembly with location countersSYMTAB.json- Symbol table in JSON formatgeneral_info.json- Program metadata (length, starting address)
Pass 2 Output (in pass2/ directory):
output.executable- Final object program
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 FIRSTThe assembler supports all standard SIC and SIC-XE instructions as defined in OBTAB.json, including:
Load/Store Instructions:
LDA,LDB,LDL,LDS,LDT,LDX,LDCHSTA,STB,STL,STS,STT,STX,STCH
Arithmetic Instructions:
ADD,SUB,MUL,DIVADDF,SUBF,MULF,DIVF(floating point)ADDR,SUBR,MULR,DIVR(register-to-register)
Control Instructions:
J,JEQ,JGT,JLT,JSUB,RSUBCOMP,COMPF,COMPR
I/O Instructions:
RD,WD,TD
Assembler Directives:
START- Define program starting addressEND- End of programBYTE- Define byte constantWORD- Define word constantRESB- Reserve bytesRESW- Reserve wordsBASE- Set base register
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
- 15-bit addresses
- 6 registers (A, X, L, B, S, T)
- Format 3 instructions (3 bytes)
- 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
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
The assembler detects and reports various errors:
- Undefined symbols
- Duplicate symbol definitions
- Invalid instruction formats
- Addressing mode violations
- Invalid operands
Input (sic.asm):
COPY START 1000
FIRST STL RETADR
LDA LENGTH
COMP ZERO
JEQ ENDFIL
ENDFIL LDA EOF
END FIRSTOutput (object program):
H^COPY ^001000^00001E
T^001000^0E^141033^001030^281030^301015^001033
E^001000
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is open source. See the repository for license details.
- System Software: An Introduction to Systems Programming by Leland L. Beck
- SIC and SIC-XE Architecture Specifications