User:Glenoakley/workspace

The Hack machine is a theoretical computer outlined in The Elements of Computing Systems. It consists of a central processing unit, random access memory, and input/output devices.

Characteristics
The Hack machine is based off of the Von Neumann architecture, with a few key differences:
 * The stored program for the machine is not contained in RAM, but in a separate read-only memory chip; instructions and data are stored apart from each other

The Hack machine functions with only two addressable processor registers:
 * The D-register is used to hold data, either from memory or from the Arithmetic logic unit.
 * The A-register is a general purpose register than can hold either raw data or a memory address.

Memory (Input/Output)
The memory chip for the Hack machine controls the RAM, ASCII-based keyboard input, and computer monitor output. Thus, the I/O devices are not treated as peripherals, but as integral components of the machine. The monitor is specified to be a black-and-white display, measuring 512 pixels wide by 256 pixels high.

The memory address bus is 15 bits wide, and the memory is organized as follows:

The screen is represented by 8,192 words (131,072 bits) of memory. A high bit (1) signifies a black pixel, while a low bit (0) signifies white. The first bit of memory determines the colour of the screen at position (1,1). The second bit determines position (1,2), the third (1,3), all the way up to position (256,512). The keyboard will transfer the ASCII value of whatever key is pressed to the keyboard word located at address 0x6000. This limits the number of simultaneous key presses to one.

Instruction Set
The Hack machine is a reduced instruction set computer (RISC). An instruction in machine code is classified as either a address instruction or a compute instruction, as defined by the following table:

The syntax of Hack assembly is made to resemble a high-level programming language. For example, MD=M+1 adds one to the memory location held in the A-register and stores it back in memory as well as in the D-register (the machine code for this instruction is 1111110111011000).