Word!CPU

From Esolang
Jump to navigation Jump to search

I have seen the Brainfuck CPU project, and a description of a INTERCAL CPU, but here is the new one!!!! Each command is 2 bytes (4 nybbles). The memory is from 0000h to 1FFFh, and there is 2 different sets of memory, the data memory and the program memory.

CPU Pins

Memory: 13-bits address space, and one extra bit to indicate program memory or data memory. Both sets of memory are read/write. The data line of the memory is 1 byte (8 bits). There is also the clock which can be changed as often as it likes and not mess up anything. Each command takes the same amount of clock cycles (always). There is 2 sets of input, 8 bits each and 1 pin of each when getting the input, 2 sets of output, 8 bits of each and 1 pin of each when sending the output.

Commands

There is 8 registers of 13 bits long indicating the memory address to access.

Block A commands: The format is (in bits) 000vvvvv vvvvvvv0 and the action is set instruction pointer to the value v (the address is always word-aligned so the 0 at the end is always a part of the address).

Block B commands: The format is (in bits) ccccxppp vvvvvvvv where c=Command, x=0 to access data memory or 1 to access program memory, p=which pointer to use for accessing memory, v=value.

  • 2 = Add (v) to value at pointer, modulo 256.
  • 3 = Move the pointer left by (v) number of spaces, wraps.
  • 4 = Move the pointer right by (v) number of spaces, wraps.
  • 5 = The value at the pointer is NAND by (v).
  • 6 = Skip backward by (v) commands if value at pointer is non-zero. (v=0 lands here, causing a infinite loop without moving the instruction pointer.)
  • 7 = Skip forward by (v) commands if value at pointer is zero. (v=0 lands on next command, just like any other command will do.)
  • 8 = If v=0 then input from first set of input, if v=1 then input from second set of input, if v=2 then send output to first set of output, if v=3 then send output to second set of output.

Block C commands: The format is (in bits) 1111xppp ccccyrrr where c=command, x=0 to access data memory or 1 to access program memory, p=which pointer to use for accessing memory, r=which register to read or modify, y=0 to access low 8 bits of register or 1 to access the hi 5 bits (the other 3 are always set to zero).

  • 0 = Put value of register to memory at pointer
  • 1 = Copy value in memory to the value of the register
  • 2 = Swap value in memory with the value of the register
  • 3 = The value of the register is NAND by the value at the pointer
  • 4 = The value at the pointer is NAND by the value of the register

Block D commands: The format is (in bits) ccccyrrr vvvvvvvv where c=command, r=which register to read or modify, y=0 to access low 8 bits of register or 1 to access the hi 5 bits (the other 3 are always set to zero), v=value.

  • 9 = Set value of register to (v).
  • A = Skip forward by (v) commands if value of the register is zero. (v=0 lands on next command, just like any other command will do.)
  • B = Skip backward by (v) commands if value of the register is non-zero. (v=0 lands here, causing a infinite loop without moving the instruction pointer.)

Examples

The programs are binary files, so these are their hexadecimal representations:

Cat

80 00 80 02 20 01 60 03 20 01 60 40

Hello World

00 12 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 0A
00 00 40 02 88 02 40 01 68 02 B0 40

Notes

  • When executing a command, it will always read the entire command first, and then read value of memory if required, and then it will execute that command and move instruction pointer.

External resources