MARIE Assembly (Instruction Set and Patterns)

Context: FIT1047_MOC · the Assignment 2 “programming interview” skill · machine model + full W3 instruction set + the branching patterns · execution semantics in Fetch-Decode-Execute and RTL (Control) Problem it solves: hand-assemble, hand-trace, and write-from-blank small MARIE programs.

Quick Revision

  • 🎯 Trigger: every instruction = 4-bit opcode + 12-bit address in a 16-bit word; only ONE working register (AC) ➔ everything routes through it.
  • ⚡ Key Constraint: SkipCond skips exactly ONE instruction — if/loops are built as SkipCond + Jump pairs; the condition constants are , , .

🧩 Machine Model

  • Memory ➔ 16-bit words, 12-bit addresses ⟹ max locations.
  • One general register ➔ the accumulator AC; special registers per Sequential Circuits (Latches, Flip-Flops, Registers).
  • Instruction word0001 000110001110 = opcode (Load) + address : “load M[18E] into AC”.
  • Hand-assembly example (workshop)Load A with label A at address assembles to (opcode nibble + address).

🎛 Instruction Set (Week 3 complete)

OpcodeAssemblyMeaning
Load X
Store X
Add X
Subt X
InputAC ← user input
Outputprint AC
Haltstop execution
SkipCond Cskip next instr. if · ·
Jump X

Week 4 additions (indirect + subroutines — patterns in MARIE Patterns (Indirect Addressing, Arrays, Subroutines))

AssemblyMeaning
LoadI X — value at the address stored at
StoreI X
AddI X
JnS X, then — call subroutine
JumpI X — return via stored address
(⚠ opcode bits for W4 instructions weren’t in the slide text — fill from the Ed e-textbook ISA table before A2.)
  • Directives so farDEC n (decimal constant) · HEX n (hex constant, HEX 0 reserves a slot) · Adr L (the ADDRESS of label L — the pointer initialiser).

🔧 Minimal Working Example — add two variables (workshop program)

      Load  A        / AC ← M[A]           (assembles to 1003 if A at 003)
      Add   B        / AC ← AC + M[B]
      Halt
A,    DEC 2          / label A: the decimal constant 2
B,    DEC 3          / label B: 3

Expected outcome: AC ends holding ; DEC is an assembler directive placing a decimal value, labels name addresses.

🔀 Branching Patterns (SkipCond + Jump — the idiom pair)

(Constructed from the taught semantics; cross-check exact style against the Ed e-textbook / W4 examples.)

  • IF AC = 0 THEN do-blockSkipCond 400 skips the Jump Else that guards the block:
      SkipCond 400   / AC = 0 ? skip next
      Jump  Else     / AC ≠ 0: bypass then-block
      ...then-block...
Else, ...
  • Countdown loop shape ➔ load counter → body → decrement (Subt One) → SkipCond 400 (done?) → Jump Loop.

✍️ Practice

⚠️ Common Mistakes

  • 💡 AC is always in the middle ➔ no memory-to-memory moves; every value passes through the accumulator.
  • 💡 SkipCond skips ONE instruction only ➔ the skipped slot is almost always a Jump — skipping a whole block directly is impossible.
  • 💡 The three condition constants for — memorise as hex, they look arbitrary in decimal.
  • 💡 DEC is not an instruction ➔ assembler directive reserving a data word; putting it in the execution path runs garbage as code (stored-program hazard).