One Instruction Set Computer
This may be the world’s shittiest CPU, but I guess this proves that any CPU, no matter how simple, can do anything.
I found out that it’s possible to make a Turing Complete ISA with one instruction and apparently I have nothing better to do other than play Overwatch and eat ramen so here I am.
The instruction implemented is subleq
which is shorthand for subtract and branch if less than or equal to zero. There are two different syntaxes for the instruction: 3 argument and 2 argument.
subleq a, b, c ; Mem[b] = Mem[b] - Mem[a]
; if (Mem[b] ≤ 0) goto c
subleq a, b ; Mem[b] = Mem[b] - Mem[a]
; goto PC + 3
sh oisc.sh init
.sh oisc.sh asm IN_FILENAME [OUT_FILENAME]
to assemble an assembly file. IN_FILENAME
is the assembly file you input and OUT_FILENAME
is the optional binary output name. Default is out.bin.sh oisc.sh sim
to run the interactive simulator. By default, the simulator runs in interactive mode.test/io_test.asm
file, change the #define INTERACTIVE_MODE
to zero, run sh oisc.sh init
and then run the simulator!For the native instruction set, there are the variations of the instruction supported: two and three argument as seen in The Instruction section.
subleq 0, 1, 3
subleq 0, 1
There are currently more instructions being implemented! They aren’t actually different instructions, just macros that get converted into subleq
. Check out src/assembler/lib/instructions.py
for more details :)
Raw data can be placed in the code using the fake op-code data
or .data
. The data can be accessed using labels.
data 8
.data 3
Labels are supported in this shitty assembly language! Just use them as you know how; on the same line or on the line before the instruction/data.
subleq A, B
A:
data 8
B: data 3
If you’re a fan of decimal, binary, or even hex, we got you covered. Oh, you’re a strange fella that uses octal? We even support that!
0x
, 0h
, $0
or suffix h
0b
, 0y
or suffixes b
, y
0o
, 0q
or suffixes o
, q
d
if you’re weird and want to be explicit
subleq 0x2, 1001010b, A
A:
data 0o345
Comments are supported using a ;
.
A:
subleq 0, 0 ; MEM[0] = 0
subleq 0, 0, A ; JMP A
In life? None. But I’m assuming you mean this project, Mr. Big Text Man.
The initial plan is to make a basic simulation of the ISA. From there, there’s a lot I’d like to do with this:
Pointers are a bitch to debug really fun.
Go for it.
Yes.
Don’t ask that question.
Okay, enough questions.
I am not responsible for any negative side effects caused by looking through this project.
Symptoms may include but are not limited to: depression, shortness of breath, nausea, abdominal pain, diarrhea, swelling, and death.
Please take OISC responsibly.