Instructions II

We concentrate on decoding C-instructions.

Review Examples

In general, Hack assembly language looks like this nonsensical code segment:

@15
D=A
(LOOP)
@n   --- "n is a variable n stored at @16"
M=M-1
@LOOP
D;JLT

Handling Components

There are three separate components of a C-instruction: the destination, the ALU math, and the jump comparison. For this part of the project, assume that you have already been given that information in a list of strings.

For example, the assembly instruction M=M-1;JEQ will be given to you as three strings: "M", "M-1", and "JEQ".

Write at least two examples for each segment of the decoding.

Destination

You may not have been aware of this, but the destination is allowed to be any subset of {A,D,M}, technically including crazy things like ADM=-1, which sets all three registers to negative one.

Jump Comparison

The jump comparison is the most straightforward. Look in the book for the table if you don’t know it off the top of your head.

ALU Math

There is a table of operations, including D-A and D|M.

Check-Expects

Every group needs to generate unit tests (check-expects) as part of finding the bugs in their code.

Last modified October 29, 2024: Another step in the plan. (81d1948)