teaching machines

CS 352 Lecture 18 – Alumem and Jumping

October 19, 2016 by . Filed under cs352, fall 2016, lectures.

Dear students,

The next homework requires doing some HDL tricks that I don’t think are necessarily intuitive. Rather than continuing to build on a wobbly foundation, let’s sketch out schematics for some of these components. We’ll visit these: DMux4Way, Inc16, LeastByte (which is not part of any homework), ALU, Bit, Register, RAM8, RAM64, and PC.

We next jump into jumps. At the assembly level, there is no such thing as if. Nor is there while or for. There’s only jmp and its conditional cousins.

It has this form:

@LABEL_TO_JUMP_TO
expr;jmp-instruction

expr can be any expression that the ALU can perform. You should avoid assigning to M in the jump expression, because that would try to write to instruction memory given that the label address was loaded in via the @ instruction. The jmp-instruction comes in eight different flavors:

mnemonic effect
JGT if expr > 0
JGE if expr >= 0
JLT if expr < 0
JLE if expr <= 0
JEQ if expr == 0
JNE if expr != 0
JMP unconditional jump
null jump to PC + 1

Let’s start by writing a forever counter:

  @i
  M=0

(LOOP)
  @i
  D=M
  M=D+1
 
  // Load up PC target.
  @LOOP
  0;JMP

Our ALU computes a few arithmetic operations, but one in particular is missing: multiplication. Let’s write a program that multiples R4 by R5 and stores the product in R6. The trick to multiplication is to expand it out to repeated addition.

Here’s your TODO list to complete before next time:

See you next class!

Sincerely,