Summary

Purpose: a quick summary of how machine language works. Aka assembly language.

Parts of the Computer

PC: Program Counter

The program counter (PC) register holds the location in ROM of the currently executing instruction.

Changing the PC:

  • Default to adding 1. (PC=PC+1)
  • Jumping sets the PC to the A register. (PC=A)

Address Register (A)

  • Holds either (1) a value or (2) a RAM memory location.
  • There is no difference. @13 loads 13 into the A register. It can then be used as either the the number 13 or the to access the memory location RAM[13].

Data Register (D)

  • Holds a value.

Memory “Register” (M)

  • M is not a real register. It always points to RAM[A].
  • When A changes, M changes automatically.

Execution

Every executable line must have an ALU instruction, even if you don’t care about it. This is “the answer” from that step. It can be 0 if you don’t care. Beware: handwritten D is close to 0. There would be some logic to using 1 as your default “I don’t care” result.

Allowed Instructions

The book contains a list of ALU instructions in Chapter 2 (where we build the ALU). They are:

0, 1, -1, x, y, !x, !y, -x ,-y, x+1, y+1,
x-1, y-1, x+y, x-y, y-x, x&y, and x|y.

Inside the ALU, x always means register D, and y can be A or M (depending on another flag).

Even though we write these instructions like mathematical expressions, they are actually short codes for setting the 6 ALU flags; for example, y-x corresponds to the flags 000111. They are not algebra. There is no x+2 or D+M operation.

Destinations

The answer from a step can be sent to A, D, or M. We design the chip at an electrical level, so you can also send the answer to more than one of them at a time; for example, MD = A+M is equivalent to the combination of D=A+M and M=A+M (in that order).

We write these as A= or MD=, but again they are not algebra.

Jumps

All comparisons are x = the result with zero. The jump instructions end the line and take effect after the computation and storage. They are called Jyyy where yyy is the top row of the table.

GT GE EQ LE LT NE
x>0 x≥0 x=0 x≤0 x<0 x≠0

Examples

  1. Add 1 to the A register: A=A+1.
  2. … and also put the same result in D: AD=A+1.
  3. … and also jump if A+1<0: AD=A+1;JLT

POST

  • Assume half of the presentation has been done.
  • Clarify the second half: storing multiple, jump, general syntax. Example: when do you use 0;JMP and when do you use D;JLE? Add in some examples with more complex things like D-1;JEQ.
Last modified September 26, 2024: Corrected statement (swap A/D). (d6657f7)