squirt is a 4-bit computer
I freaking love making useless computers!!!
I had been rotating this idea in my head for a while, and the original plan was to try to make this using Minecraft logic gates, but that seems like a pain in the ass so I didn't. INSTEAD I just wrote a VM in Odin one day out of a random stroke of inspiration.
Squirt is of course, a stack machine. A whopping 256 nibbles of stack. Can't work with registers when every instruction is 4 BITS!! That means there are only 16 of them. Each instruction is immediately followed by a signed 4-bit integer (dubbed JP (like from redline)) that moves the instruction pointer n*2 nibbles forward/backwards in memory. You could argue that this makes each opcode a single byte instead of just 4bits, but if you argue with me then I might shrink your head and tie it to my rosary of annoying-people-heads.
- 0 PUSH JP to stack, then jump forward 1
- 1 POP nibble from stack
- 2 DUPLICATE the top nibble on stack
- 3 SWAP the top two nibbles on the stack
- 4 RECEIVE input nibble from IO
- 5 SEND top stack nibble to IO
- 6 bitwise AND
- 7 bitwise OR
- 8 bitwise NOT
- 9 GREATER than (not sure how to capitalize this one)
- a EQUALS (push 1 if top two nibbles are equal, 0 otherwise)
- b conditional JUMP (if top nibble is zero, move forward 1. otherwise follow JP)
- c ADD
- d SUBTRACT
- e MULTIPLY
- f DIVIDE
"Input" and "Output" for a squirt computer is a bit more primitive than something like a tty's stdio. According to the real divine scripture that I penned after receiving a vision from my goddess Eris, a squirt computer's input and output are two pieces of wet string. You can tie them to the strings of other squirt computers to relay information, but that would be lewd.
Since I wanted to be able to print text with this in an example program, I felt it necessary to create a text encoding "standard" that makes frequently-used characters more accessible to a computer that can't count higher than 15.
example programs
I did not feel it was necessary to make an assembly script for this computer. I wrote both of these programs in hexedit(1) and yes, I did feel like Mel while doing it.
00 08 08 01 0F 08 01 05 0D 01 0B 02 08 02 0C 07 01 09 08 01 08 02 0D 01 0D 01 06 0D 05 21 00 A1 B2 5C 10
^ helloworld.bin - It prints "Hello, World!" and exits. A large majority of this program is just putting text on the stack. The last 6 bytes are what actually prints everything.
09 21 31 21 21 03 31 91 B7 0C C1 03 51 51 36 04 C1 04 51 5D 21 21 03 31 91 B7 0C C1 03 51 51 36 04 C1 04 51 5D 00 01 0A 03 0D 01 0F 01 08 02 01 0C 02 0A 01 01 06 0B 02 06 09 01 0D 02 01 08 03 08 02 0F 01 01 05 0F 01 02 01 0A 03 0D 02 0C 02 0B 02 0A 01 09 01 0D 02 01 0C 02 02 08 03 01 0A 01 01 0D 02 0E 02 03 08 08 01 0D 01 0D 01 02 08 03 01 06 09 01 0D 02 01 0F 01 08 02 01 0B 02 06 06 03 01 07 08 02 01 0C 02 06 0D 01 0D 02 0D 02 08 02 03 01 21 00 A1 B2 5C 11 31 21 00 A1 B4 01 31 D6 31 01 31 D1 33 00 13 11 09 21 00 A1 B7 00 13 00 00 00 17 31 21 00 A5 00 00 00 17 B2 35 08 08 00 13 00 17 01 0F 08 01 00 13 00 17 0C 05 0B 06 00 13 00 17 0E 05 0D 05 00 13 00 17 09 07 0C 06 00 13 00 17 0B 06 00 15 00 00 00 17 21 00 A1 B2 5C 10 00 17 00 00 00 00 00 00 00 16 00 00 00
^ beer.bin - Counts down from 99 bottles of beer on the wall until there is NOTHING! I will not try to explain how this program works as I have already forgotten. This also assumes that your squirt VM has exactly 256 bytes of memory (mine does!) so that it can abuse a u8 overflow to loop back to the beginning.
────────────────────────────────
Last updated 25S07
Incoming: itf4[1], projects[2]