TactivergeLite

Lite / Engineering Complex Systems / Week 25

The contract between code and silicon

Code compiled years ago still runs on brand-new processors with completely different insides. What promise makes that possible?

About 35 min · 3 goals · Checked by automated tests · Full interactive version

Why should I care?

An instruction set is one of the most important interfaces in engineering: software teams target it and hardware teams implement it, and neither has to know the other's details. Understanding it explains compilers, emulators and why some chips can't run some apps.

Predict

BUILD 008's Nibble machine has LOAD, ADD, STORE, JNZ and HALT but no SUBTRACT. Can it subtract 1?

  1. No, never
  2. Yes: ADD 15 in 4-bit arithmetic is the same as subtracting 1
  3. Only with a new chip
  4. Only for even numbers
Guess first, then reveal

In 4 bits, 15 is −1 in two's complement: adding it carries out of the top bit and leaves one less. ISA designers often leave instructions out when software can build them from others.

Discover

Open the Virtual Computer at Level 4 and read the five instructions. Before attempting the multiply task, write a three-line program that copies M0 into M3, run it step by step, and note what each instruction changes: the register A, a flag, memory or the program counter.

What the interactive shows (text version)

The Virtual Computer Level 4 shows the Nibble machine: register A, flags Z and C, 16 data cells and a program of up to 16 lines. LOAD a copies M[a] into A, ADD a adds M[a] into A (4 bits, carry into C), STORE a copies A into M[a], JNZ p jumps to line p if A was not zero, HALT stops.

You can also open the interactive on the full site when you have a faster connection.

Watch (optional)

Watch for: Watch how each instruction is a bit pattern with an operation part and an address part, and how a jump changes which instruction comes next.

Shows instructions as bit patterns with an opcode and an address field, then runs a small program step by step.

“Instructions & Programs: Crash Course Computer Science #8” by CrashCourse (opens YouTube; streaming video uses a lot of data)

The video is optional. Everything you need is in this lesson's text.

Understand

What an ISA promises

An instruction set architecture defines: the registers visible to programs (Nibble has one, A, plus flags Z and C); the instructions and exactly what each does; their encoding as bits; how operands are found (addressing modes: a constant, a register, a memory address); and how memory and I/O look to software. Anything not in the contract is free for the hardware designer to change.

Architecture vs microarchitecture

Two chips implementing the same ISA can be utterly different inside: one takes 3 clock cycles per instruction, another overlaps many instructions in a pipeline. Both run the same program and get the same answers; only the speed differs. That separation is why software lasts longer than any one chip.

Design styles

Accumulator machines (like Nibble) keep one working register. Load–store / RISC machines (like RISC-V or the TV-16 teaching format) do arithmetic only between registers, with separate load and store instructions. CISC machines allow memory operands in arithmetic. Fewer, simpler instructions make hardware simpler; richer ones make programs shorter.

Explain it another way

Intuitive

The ISA is the menu of a restaurant. Diners (programs) order from the menu; the kitchen (hardware) can be reorganised any way it likes, as long as every dish comes out as described.

Technical

An ISA also fixes word size, endianness, the exception and interrupt model, and privilege levels. Extensions (like vector instructions) are added as optional parts of the contract.

Mathematical

With a k-bit opcode field you can name at most 2^k operations; with an r-bit register field, 2^r registers. Nibble: 4-bit opcode (16 possible, 5 used), 4-bit operand (16 addresses).

Applied

Emulators run one ISA's programs on another by decoding each instruction in software. Phone makers can license the Arm ISA and design their own microarchitectures, and RISC-V is an open ISA anyone may implement.

Worked example 1

Write a Nibble program that sets M3 to M0 + M0.

LOAD 0 (A ← M0), ADD 0 (A ← A + M0), STORE 3 (M3 ← A), HALT. Four instructions, and the 4-bit result wraps if M0 ≥ 8.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. Which of these is NOT part of an ISA?
Practice 2. Two processors implement the same ISA. One is three times faster. What can you say?

operations

Apply it

Propose one new instruction for the Nibble machine that would make its programs shorter. Specify it like an ISA manual: mnemonic, opcode (choose an unused one), what it does to A, flags, memory and PC, and one example.

Reflect

Why might an ISA designer deliberately leave out an instruction that programmers would find useful?

Write your answer on paper or in your own notes. Lite never stores what you write.

← A state machine in softwareInstructions are just numbers →