← Back to projects

Systems programming

A two pass SIC/XE assembler in one C++ program

This course project translates SIC/XE assembly into object code. The first pass assigns addresses and builds a symbol table. The second resolves operands, chooses addressing modes, and emits header, text, modification, and end records.

C++SIC/XEObject codeHash table

Assembly pipeline

Source becomes a relocatable object program

Parse source lines
Pass 1 and SYMTAB
Pass 2 encoding
Text records
H, T, M, E output

Pass 1

Addresses and symbols come first

The location counter starts at the operand of START. Each instruction advances it by format length; directives such as WORD, BYTE, RESW, and RESB apply their own sizes. Labels are inserted into a chained hash table, and duplicate symbols are reported as the listing is built.

Formats 1 to 4

The opcode table records the base format, while a leading plus selects extended format 4.

Directives

START, END, BASE, NOBASE, WORD, BYTE, RESW, and RESB affect state without all producing object bytes.

Symbols

A compact hash table maps labels to six digit addresses for operand resolution in pass 2.

Pass 2

Addressing flags determine the final instruction

The encoder handles immediate, indirect, indexed, program counter relative, base relative, and extended addressing. Format 4 symbol references also produce modification records. Text records stop at 30 bytes and split across reserved storage gaps.

Syntax Meaning Encoding effect
#VALUE Immediate n = 0, i = 1
@VALUE Indirect n = 1, i = 0
VALUE,X Indexed x = 1
+JSUB TARGET Extended e = 1 with a 20 bit address and modification record

Object program

The output follows the standard record layout

H^COPY  ^000000^00107A
T^000000^1E^...
M^000004^05
E^000000

The sample COPY program exercises device I/O, subroutines, base addressing, format 4 calls, reserved memory, and byte constants.

Build and run

A Make target is enough

make
./assembler input.asm

The assembler writes the generated records to output.obj and prints both pass listings to the terminal.