# teaching machines

## CS 352 Lecture 18 – Alumem and Jumping

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

@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:

• Plan for our exam on Friday, October 28. Eligible topics include logical and bitwise operations, the representation of integers, Karnaugh maps, HDL, and the fundamental hardware components that we’ve discussed in class—and the ideas behind them.

See you next class!

Sincerely,