IAS Assembly & Machine Code

The 4-mark Q1(c) every semester: write the symbolic (assembly) code and its machine-code encoding for a small program. Master the method once — it never changes.

The accumulator method

There is one working register, AC. Every program is: LOAD the first value into AC, then ADD/SUB the rest, then STOR the result.
  • LOAD M(X) → AC = M(X)
  • ADD M(X) → AC = AC + M(X)
  • SUB M(X) → AC = AC − M(X)
  • STOR M(X) → M(X) = AC

Encoding a line to machine code

Each instruction = 8-bit opcode + 12-bit address. Steps:
opcode8 bits0 – 7address12 bits8 – 19
One IAS instruction — 20 bits
1. Opcode from the table
LOAD=00000001 · ADD=00000101 · SUB=00000110 · STOR=00100001
2. Address → 12-bit binary
write each hex digit as 4 bits
3. Machine code = [opcode 8 bits] [address 12 bits]
08A = 0 8 A = 0000 1000 1010
08B = 0000 1000 1011      08C = 0000 1000 1100
08D = 0000 1000 1101      08E = 0000 1000 1110

Example 1 — basic add: M(08A) = M(08B) + M(08C)

AssemblyOpcode (8)Address (12)
LOAD M(08B)0000 00010000 1000 1011
ADD  M(08C)0000 01010000 1000 1100
STOR M(08A)0010 00010000 1000 1010

Example 2 — Autumn 2025 Q1(c)

Add M(08A) and M(08B), subtract the sum from M(08C), write to M(08D).
i.e. M(08D) = M(08C) − M(08A) − M(08B). (Load the positive term 08C first.)
AssemblyOpcode (8)Address (12)
LOAD M(08C)0000 00010000 1000 1100
SUB  M(08A)0000 01100000 1000 1010
SUB  M(08B)0000 01100000 1000 1011
STOR M(08D)0010 00010000 1000 1101

Example 3 — Spring 2026 Q1(c)

Subtract (M(08A)+M(08B)) from (M(08C)+M(08D)), write to M(08E).
i.e. M(08E) = M(08C) + M(08D) − M(08A) − M(08B).
AssemblyOpcode (8)Address (12)
LOAD M(08C)0000 00010000 1000 1100
ADD  M(08D)0000 01010000 1000 1101
SUB  M(08A)0000 01100000 1000 1010
SUB  M(08B)0000 01100000 1000 1011
STOR M(08E)0010 00010000 1000 1110

Example 4 — “double a value” (Autumn 2024 Q1a)

Read M(X) and write 2 × M(X) back to X. Use LSH (shift left = ×2).
LOAD M(X)      ; AC = M(X)
LSH            ; AC = AC × 2
STOR M(X)      ; M(X) = 2 × M(X)
Tip: when the target expression starts with a minus (e.g. −A − B + C), reorder so a positive term is loaded first: C − A − B → LOAD C, SUB A, SUB B, STOR. Try any of these in the Live IAS Assembler →