\(5.4.\)Hack Computer

1.Hack computer abstraction

  • A computer capable of running programs written in the Hack machine language.

2.CPU operations

Alt text
  • If the instruction includes D And A, CPU is going to manipulate the respective D and A registers.

  • If the instruction ia an A instruction like @17, CPU is going to take the 15-bit data value and store them inside the A register. This value is emitted by addressM.

  • If the instruction's right hand side includes M like M = M + 1, this value is read from inM interface.

  • If the instruction's left hand side includes M, then the value output should be stored in the data memory of the selected memory register.

    • As we discuss in the CPU, we have to provide what things we want to write, where to write and the control bits to write something to the data memory. As a result, the ALU output is emitted by outM, and the writeM is asserted.
  • If we have a jump situation @100, D = D - 1; JEQ. , we want to jump to the address that was specified before(100, in this case):

    • If reset == 0, CPU logic uses the jump bits and the ALU output to decide whether or not there should be a jump.
    • If there is a jump, PC = A
    • Else, PC++
    • The updated PC value is emitted by pc.
    • If reset == 1, pc emits 0, causing a program restart

3.Memory abstraction

Alt text
  • Three different segments:

    • Address 0 to 16383(16k): data memory
    • Address 16384 to 24575(next 8k): screen memory map
    • Address 24576: keyboard memory map

4.Memory implementation

  We bulid our memory from three different sub-chips:

  • RAM: 16-bit 16K RAM chip
  • Screen: 16-bit/8K memory chip with a raster display side-effect.
  • Keyboard: 16-bit register with a keyboard side-effect.

  \(a.\)RAM

![[Pasted image 20240406103441.png]]

  • The inputs and outputs of RAM16 are identical to the inputs and outputs of the overall memory chip.
  • So whoever builds the chip has to make sure to take the outside inputs and outputs and make connections that will funnel these value into the inner chip box, such as RAM 16K.

  \(b.\)Screen

![[Pasted image 20240406104348.png]]

  • We use a special built-in 8K screen chip that knows how to automatically refresh a connected display unit.
    • It's a RAM chip, which has a nice side effect of refreshing a connected display unit.

  \(c.\)Keyboard

  • We use a built-in Keyboard chip featuring a keyboard capture side-effect, which is that it always reflects what the user is pressing on the keyboard.

5.Instruction memory

  \(a.\)Intro

  • We implement this instruction memory using a chip called ROM 32K.

  • We can loading a program in this way:

    • Hardware inplementation: plug-and-play ROM chips: We put our machine instruction code into a ROM chip. We take this RAM chip, plug it into the computer. We press the reset button, and the computer will start executing this particular program.

      • If we want to run another program, we take the chip out and plug in another chip.

  \(b.\)ROM interface

  • It's a read-only device.
  • Contains a sequence of Hack instructions (program).
  • The output of of the ROM is always the contents of the register that is selected by the address input.
  • Since the pc always emits the address of next instruction, if we feed this address into ROM, we are guaranteed that ROM will always admit a 16-bit value that we can treat as the current instruction.

6.Hack computer implementation

  • We first connect to the CPU the instruction memory which we call ROM. The instruction input of the CPU is taken from the output of instruction memory.
  • In the process of executing this instuction, we are going to compute the address of the next instruction. This address is emitted by pc.
  • The address goes all the way into the address of the instruction unit, and the unit will emit the next instruction that has to be executed in the next cycle.

  • To do something useful with the outputs, we connect outputs to memory unit.
  • We take the output of the memory, and connect it back into the CPU

  • The input and output units are the only two things the computer users sees when he works.
  • With this computer is a display unit, a keyboard and the reset button.

  • This is the overall computer architect!!!