SUBBIG
SUBBIG (SUBtract and jump if BIGger than zero) is an OISC by User:ChuckEsoteric08.
Description
SUBBIG has memory-mapped commands, with them being at the start of a memory and everything else being 0.
a b c
Subtract memory address b from memory address a and jump to memory address c if result was bigger than zero. If you try to goto to address -1 program halts
I/O
a -1 c
Would set memory address a to user input.
-1 b c
Would output memory address b.
I/O Could be either character-based or integer-based depending on implementation.
Programming in SUBBIG
For simplicity we will use assembly-like syntax. Where
X:Y
Means "Declare label X with value Y". And :X would return location of label X.
a b NEXT
Means "Go to the next memory address".
a b HALT
Means "Execute command and halt".
Writing a program that prints "Hi"
Note that this program would only work in a version with character-based I/O:
-1 :H NEXT -1 :I NEXT -1 :! HALT H:72 i:105 !:33
First three lines are dedicated for outputing value of value of labels "H", "i" and "!" with last line ending in "HALT" so the program would halt without executing last line. Last line of code contains value of this labels.
In normal SUBBIG it would look like this:
-1 10 3 -1 11 6 -1 12 -1 72 105 33
Writing Truth-machine
This one is a little bit harder.
Version for character-based I/O
:X -1 NEXT :X :SUB :preloop -1 :X NEXT :X :NEG HALT preloop::X ADD :loop loop:-1 :X :loop X:0 SUB:48 NEG:-1 ADD:-48 0 0
First you need to type either 0 or 1 and store it in X. Then subtract 48 and if result was bigger than 0 goto label preloop where 48 is added to X and goto label loop where it prints X infinitly. Else We would print 0 and halt.
Here it is in normal SUBBIG:
19 -1 3 19 20 13 -1 20 9 19 21 -1 19 22 16 -1 19 16 0 48 -1 -48 0 0
Version with integer-based I/O
This version is a lot easier to do than in character-based I/O version:
:X -1 :loop -1 :X HALT loop:-1 :X :loop X:0 0 0
In normal SUBBIG:
9 -1 6 -1 9 -1 -1 9 6 0 0 0
Examples
Self-interpreter
Program whis is interpreted starts at PROG label
# Zeroes A, B and C START::A :A NEXT :B :B NEXT :C :C NEXT # ZERO = -PC :ZERO :PC NEXT # A = *PC :A1 :A1 NEXT :A1 :ZERO NEXT :ZERO :ZERO NEXT :ZERO A1:0 NEXT :A :ZERO NEXT :ZERO :ZERO NEXT # A += LEN :A :NEGL NEXT # PC +=1 :PC :NEG NEXT # B = *PC :B1 :B1 NEXT :B1 :ZERO NEXT :ZERO :ZERO NEXT :ZERO B1:0 NEXT :B :ZERO NEXT :ZERO :ZERO NEXT # B += LEN :B :NEGL NEXT # PC +=1 :PC :NEG NEXT # C = *PC :C1 :C1 NEXT :C1 :ZERO NEXT :ZERO :ZERO NEXT :ZERO C1:0 NEXT :C :ZERO NEXT :ZERO :ZERO NEXT # A = A-B A:0 B:0 :BIG # PC +=1 :PC :NEG START # Save raw C :PC :PC NEXT :ZERO :C NEXT :PC :ZERO NEXT :ZERO :ZERO NEXT # Increment C, if nonzero then jump BIG::C :NEG :JMP # else halt :C :C HALT # PC += LEN JMP::PC :NEGL START ZERO:0 PC::PROG NEG:-1 C:0 NEGL:-111 PROG:
When compiled it becomes:
78 78 3 79 79 6 108 108 9 105 106 12 22 22 15 22 105 18 105 105 21 105 0 24 78 105 27 105 105 30 78 109 33 106 107 36 46 46 39 46 105 42 105 105 45 105 0 48 79 105 51 105 105 54 79 109 57 106 107 60 70 70 63 70 105 66 105 105 69 105 0 72 108 105 75 105 105 78 0 0 96 106 107 0 106 106 87 105 108 90 106 105 93 105 105 96 108 107 102 108 108 -1 106 109 0 0 110 -1 0 -111