Hack computer

Uses your system voice; voice and rate in settings.

Snapshot

≈ 8 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

The Hack computer is a theoretical computer design created by Noam Nisan and Shimon Schocken and described in their book, The Elements of Computing Systems: Building a Modern Computer from First Principles. In using the term “modern”, the authors refer to a digital, binary machine that is patterned according to the von Neumann architecture model. The Hack computer is intended for hands-on virtual construction in a hardware simulator application as a part of a basic, but comprehensive, course in computer organization and architecture. One such course, created by the authors and delivered in two parts, is freely available as a massive open online course (MOOC) called Build a Modern Computer From First Principles: From Nand to Tetris. In the twelve projects included in the course, learners start with a two input NAND gate and end up with a fully operational virtual computer, including both hardware (memory and CPU) and software (assembler, VM, Java-like programming language, and OS). In addition to the hardware simulator used for initial implementation of the computer hardware, a complete Hack computer emulator program and assembler that supports the projects described in the book and the on-line course is also available at the author's web site.

The Hack computer is a theoretical computer design created by Noam Nisan and Shimon Schocken and described in their book, The Elements of Computing Systems: Building a Modern Computer from First Principles. In using the term “modern”, the authors refer to a digital, binary machine that is patterned according to the von Neumann architecture model. The Hack computer is intended for hands-on virtual construction in a hardware simulator application as a part of a basic, but comprehensive, course in computer organization and architecture. One such course, created by the authors and delivered in two parts, is freely available as a massive open online course (MOOC) called Build a Modern Computer From First Principles: From Nand to Tetris. In the twelve projects included in the course, learners start with a two input NAND gate and end up with a fully operational virtual computer, including both hardware (memory and CPU) and software (assembler, VM, Java-like programming language, and OS). In addition to the hardware simulator used for initial implementation of the computer hardware, a complete Hack computer emulator program and assembler that supports the projects described in the book and the on-line course is also available at the author's web site. C-instruction: dest=comp;jump, either the dest or jump may be empty giving two options dest=comp or comp;jump The C-instruction is bit-field encoded as follows: 111a c 1 c 2 c 3 c 4 c 5 c 6 d 1 d 2 d 3 j 1 j 2 j 3 1 – the most significant bit of a C-instruction is "1" 11 – these second two bits are ignored by the CPU and, by convention, are each always set to "1" a – this bit specifies the source of the "y" operand of the ALU when it is used in a computation c 1 -c 6 – these six control bits specify the operands and computation to be performed by the ALU d 1 -d 3 – these three bits specify the destination(s) for storing the current ALU output j 1 -j 3 – these three bits specify an arithmetic branch condition, an unconditional branch (jump), or no branching The Hack computer encoding scheme of the C-instruction is shown in the following tables. In these tables, A represents the value currently contained in the A-register D represents the value currently contained in the D-register M represents the value currently contained in the data memory register whose address is contained in the A-register; that is, M == RAM[A] C-instructions direct the ALU computation engine and program flow control capabilities of the Hack computer. The instruction syntax is defined by three fields, referred to as "comp", "dest", and "jump". The comp field is required in every C-instruction. The C-instruction syntax is "dest=comp;jump". The "=" and ";" characters are used to delimit the fields of the instruction. If the dest field is not used, the "=" character is omitted. If the jump field is not used, the ";" character is omitted. The C-instruction allows no internal spaces. The comp field must be one of the 28 documented mnemonic codes defined in the table above. These codes are considered distinct units; they must be expressed in all-caps with no internal spaces. It is noted that the 6 ALU control bits could potentially specify 64 computational functions; however, only the 18 presented in the table are officially documented for recognition by the assembler. The dest field may be used to specify one or more locations to store the result of the specified computation. If this field is omitted, along with the "=" delimiter, the computed value is not stored. The allowed storage location combinations are specified by the mnemonic codes defined in the table above. The jump field may be used to specify the address in ROM of the next instruction to be executed. If the field is omitted, along with the ";" delimiter, execution continues with the instruction immediately following the current instruction. The branch address target, in ROM, is provided by the current value of the A register if the specified branch condition is satisfied. If the branch condition fails, execution continues with the next instruction in ROM. Mnemonic codes are provided for six different comparisons based on the value of the current computation. Additionally, an unconditional branch is provided as a seventh option. Because the comp field must always be supplied, even though the value is not required for the unconditional branch, the syntax of this instruction is given as "0;JMP". The branch conditions supported are specified in the table above. // Adds 1+...+100 int cnt = 1; int sum = 0; while (cnt The contents of the Hack assembly language source file are shown in the second column in bold font. Line numbers are provided for reference in the following discussion but do not appear in the source code. The Hack machine code produced by the assembler is shown in the last column with the assigned ROM address in the preceding column. Note that full-line comments, blank lines, and label definition statements generate no machine language code. Also, the comments provided at the end of each line containing an assembly language instruction are ignored by the assembler. The assembler output, shown in the last column, is a text string of 16 binary characters, not 16-bit binary integer representation. Note that the instruction sequence follows the pattern of A-instruction, C-instruction, A-instruction, C-instruction, ... . This is typical for Hack assembly language programs. The A-instruction specifies a constant or memory address that is used in the subsequent C-instruction. All three variations of the A-instruction are illustrated. In line 11 (@100), the constant value 100 is loaded into the A register. This value is used in line 12 (D=D-A) to compute the value used to test the loop branch condition. Since line 4 (@cnt) contains the first appearance of the user-defined variable "cnt", this statement binds the symbol to the next unused RAM address. In this instance, the address is 16, and that value is loaded into the A register. Also, the M pseudo-register also now references this address, and RAM[16] is made the active RAM memory location. The third use of the A-instruction is seen in line 21 (@LOOP). Here the instruction loads the bound label value, representing an address in ROM memory, into the A register and M pseudo-register. The subsequent unconditional branch instruction in line 22 (0;JMP) loads the M register value into the CPU's program counter register to effect control transfer to the beginning of the loop. The Hack computer provides no machine language instruction to halt program execution. The final two lines of the program (@END and 0;JMP) create an infinite loop condition which Hack assembly programs conventionally use to terminate programs designed to run in the CPU emulator.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1348686990 under CC BY-SA 4.0; modifications have been made.