Assembler Manual

Processor Architecture

Level 16 features an 8-bit Harvard-architecture computer with separate instruction and data memory:

Assembler Panel

When a ROM is present on the canvas, an «Assembler» tab appears in the right panel. It contains:

Instruction Format

Each instruction is 1 byte. Upper 4 bits (7:4) = opcode, lower 4 bits (3:0) = operand (address 0–15).

 7 6 5 4  3 2 1 0
┌────────┬─────────┐
│ Opcode │ Operand │
└────────┴─────────┘

Instruction Set

MnemonicOpcodeActionExample
NOP 0 No operation NOP0x00
ADD 1 Acc = Acc + RAM[X] ADD 30x13
SUB 2 Acc = Acc − RAM[X] SUB 70x27
AND 3 Acc = Acc & RAM[X] AND 10x31
OR 4 Acc = Acc | RAM[X] OR 20x42
LDA 5 Acc = RAM[X] LDA 50x55
STA 6 RAM[X] = Acc STA 100x6A
JMP 7 PC = X (unconditional jump) JMP 00x70
JZ 8 if Acc=0: PC = X (conditional jump) JZ 70x87
HLT 15 Stop clocking HLT0xF0

Syntax Rules

Example: Compilation and Execution

; Simple program — 4 instructions
LDA 5
ADD 3
STA 0
HLT

After pressing ▶ Execute, the program compiles and immediately runs. The log panel shows compilation lines:

[AsmPanel] === Compile & Run ===
[Asm]  ROM[0] = 0x55  (LDA 5)
[Asm]  ROM[1] = 0x13  (ADD 3)
[Asm]  ROM[2] = 0x60  (STA 0)
[Asm]  ROM[3] = 0xf0  (HLT)
[Asm] Compile done: 4 instruction(s)
[Asm] ROM[0..3]: 0x55 0x13 0x60 0xf0

Then — execution lines (odd ticks only — rising edge):

[AsmPanel] PC=0, play
[CPU] Tick 1   PC=0  →  LDA 5   [0x55]
[CPU] Tick 3   PC=1  →  ADD 3   [0x13]
[CPU] Tick 5   PC=2  →  STA 0   [0x60]
[CPU] Tick 7   PC=3  →  HLT     [0xf0]
[HLT] PC=4 (prev=3) instruction=0xf0 → HALT detected, stopping

Important: RAM Initialization

LDA 5 loads the value from RAM[5], not the constant 5. Since all RAM cells are initially zero, the accumulator after LDA 5 will be 0. ADD 3 adds RAM[3] = 0. The result is always 0.

For meaningful data work, initialize RAM via the browser console (F12 → Console) before pressing «Execute»:

const ram = graph.findNodesByType('tc/RAM')[0];
ram.memory[5] = 5;   // RAM[5] = 5
ram.memory[3] = 3;   // RAM[3] = 3

After initialization and execution of LDA 5; ADD 3; STA 10; HLT, RAM[10] will contain 8.

Example: Working with Data

; Load value from RAM[10], double it, store in RAM[11]
LDA 10    ; Acc = RAM[10]
ADD 10    ; Acc = Acc + RAM[10] = RAM[10] * 2
STA 11    ; RAM[11] = Acc
HLT

Example: Conditional Jump (JZ)

; JZ test: if accumulator = 0 → jump to address 5
LDA 0     ; Acc = RAM[0] = 0
ADD 0     ; Acc = 0 + 0 = 0 (Zero flag = 1)
JZ  5     ; Jump to addr 5 (triggered)
STA 15    ; ← skipped
HLT       ; ← skipped
NOP       ; address 5 — jump target
HLT       ; stop here

Reading Memory via Console

// Check RAM contents after program execution
const ram = graph.findNodesByType('tc/RAM')[0];
console.log('RAM[10]:', ram.memory[10]);
console.log('RAM[11]:', ram.memory[11]);

// Check ROM contents after compilation
const rom = graph.findNodesByType('tc/ROM')[0];
const hex = Array.from(rom.memory.slice(0, 8))
  .map(b => '0x' + b.toString(16).padStart(2, '0')).join(' ');
console.log('ROM[0..7]:', hex);

How an Instruction Executes (2 Ticks per Command)

Each instruction takes exactly two Clock ticks. The first (rising edge 0→1) fetches and executes, the second (falling edge 1→0) latches the result:

Tick N   (0→1): PC outputs address → ROM → Splitter → Decoder → ALU/RAM
                  Result is ready but not yet written to registers.

Tick N+1 (1→0): Registers capture data. PC does not change.

This is why the log only shows instructions on odd ticks (1, 3, 5, …) — the rising edge when the instruction actually executes.

Log Panel Prefixes

PrefixWhen it appears
[Asm]Compilation: each instruction and final ROM dump
[AsmPanel]Pressing ▶ Execute — compilation and launch stages
[CPU]Every odd tick — executing instruction
[HLT]HALT detected — clocking stopped

The log clears on each ▶ Execute press before compilation. History is not preserved between runs.

Example: Unconditional Jump (JMP)

; Infinite loop between addresses 2 and 3
LDA 0
STA 15
JMP 2     ; ← loop back to JMP
HLT       ; never executes

The program will loop — HLT never triggers. Press ⏸ Pause on the Clock Control panel to stop. Verify in the log that PC loops on 2.

Example: Data Tracing

With RAM[10] = 7 (set via console):

LDA 10    ; Acc = RAM[10]
ADD 10    ; Acc = Acc + RAM[10] = RAM[10] * 2
STA 11    ; RAM[11] = Acc
HLT
TickPCInstructionAccRAM[10]RAM[11]
10LDA 10770
31ADD 101470
52STA 1114714
7HLT

Shortcut Keys

KeyAction
F9Run level verification
F12Open developer console
DeleteDelete selected element

Known Limitations

Go to the simulator →