GHost CPU

From Esolang
Jump to navigation Jump to search

GHost CPU (GHC) is one of the languages used in the ICFP contest 2014.

GHC is designed to resemble an 1980s 8-bit microcontroller. It has a read-only code memory made of 256 instructions, a read-write data memory made of 256 bytes, 8 general-purpose registers of one byte size each, and a program counter. The instructions all operate on one-byte values. The instructions include copy, add/subtract (modulo 256), bitwise and/or/xor, unsigned less/greater/equal compare and branch if the comparison is true, multiplication (low byte of result only), unsigned division (quotient only), or operating system call. The arithmetic instructions are read-modify-write style, as in, the output argument is always the same as the first input argument (the divisor for divison, the input that is not negated for subtraction). Each input or output argument can be one of the eight general registers, the memory byte at a fixed address, the memory byte at the address given by one of the general purpose registers (with no offset), or, for input arguments only, a constant byte or the program counter. In addition, for only the copy instruction, the output argument can be the program counter too, thus allowing an indirect jump. The compare and branch instructions branch to a fixed address in the instruction memory. The operating system interface use fixed registers as input or output, but which registers mean what depends on the specific system call.

In the story of the contest, the LamCo company used this language to control the ghost AIs in their arcade computer running a Pacman-like game. There is a separate instance of GHC for each ghost, each ran by a separate microcontroller on the motherboard of the machine. The operating system call instruction of these GHCs is wired up to interact with the Pacman-like game, as in, read information about the map and state of Pacmans and ghosts, and set the direction that the ghost is walking towards.

External links