SIC-1 is an 8-bit Single Instruction computer. The only instruction it supports is SUBLEQ: Subtract and Branch if Less than or Equal to Zero. The instruction has three operands: A, B, and C. The instruction subtracts the value at address B from the value at address A and stores the result at address A. If the result is less than or equal to zero, the instruction jumps to address C. Otherwise, it proceeds to the next instruction.
The SIC-1 computer has an address space of 256 bytes, and and 8-bit program counter. The first 253 bytes are used for the program memory, and the last 3 bytes are used for input, output, and for halting the computer:
Address | Label | Read | Write |
---|---|---|---|
253 | @IN | ui pins |
Ignored |
254 | @OUT | Returns 0 | uo pins |
255 | @HALT | Returns 0 | Ignored |
Setting the program counter to 253, 254, or 255 will halt the computer.
Each instruction is 3 bytes long, and the program counter is incremented by 3 after each instruction, except when a branch is taken.
For more information, check out the SIC-1 Assembly Language Reference.
Each instruction takes 6 cycles to execute, regardless of whether a branch is taken or not. The execution of an instruction is divided into the following stages:
The pseudocode for the execution cycle is as follows:
(1) A <= memory[PC]
(2) B <= memory[PC+1]
(3) C <= memory[PC+2]
(4) valA <= memory[A]
(5) valB <= memory[B]
(6) result <= valA - valB
memory[A] <= result
if result <= 0:
PC = C
else:
PC = PC + 3
The uio
pins are used to load a program into the computer, and to control the computer:
uio pin | Name | Type | Description |
---|---|---|---|
0 | run | input | Start the computer |
1 | halted | output | Computer has halted |
2 | set_pc | input | Set the program counter to the value on ui pins |
3 | load_data | input | Load the value from the ui pins into the memory at the PC |
4 | out_strobe | output | Pulsed for one clock cycle when the computer writes to @OUT (uo pins) |
You can use the [https://jaredkrinke.itch.io/sic-1](online SIC-1 app) to compile and simulate your SIC-1 programs. Click on "Run game" and then "Apply for the job", close the "Electronic mail" popup. Paste the code and click on "Compile" (on the bottom left). You'll see the compiled code in the "Memory" window on the right, and will be able to step through the code.
To load a program and run a program, follow this sequence:
ui
pins to 0 (target address)load_pc
pinui
pins to the value you want to loadload_data
pinui
pins to the address you want to start at (usually 0)set_pc
pinrun
pin to 1. The computer will start running the program, and the halted
pin will go high when the program is done.If you want to step through the program, you can pulse the run
pin to advance one instruction at a time.
# | Input | Output | Bidirectional |
---|---|---|---|
0 | in[0] | out[0] | run |
1 | in[1] | out[1] | halted |
2 | in[2] | out[2] | set_pc |
3 | in[3] | out[3] | load_data |
4 | in[4] | out[4] | out_strobe |
5 | in[5] | out[5] | |
6 | in[6] | out[6] | |
7 | in[7] | out[7] |