Skip to content
Tactiverge

School/□ Systems Engineer/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

1.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.

  • ◇ Explain what an ISA defines: registers, instructions, encodings and addressing modes.
  • ◇ Distinguish architecture (the contract) from microarchitecture (the implementation).
  • ◇ Run and explain a short program on a minimal accumulator machine.

2.Watch

→ 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.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

3.Predict

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

Guess first. Being wrong here is how the surprise works.

4.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.

Can't use the interactive? Read a description instead

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.

5.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

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?

6.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

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.

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

  • A faster chip must have a better instruction set.
    ✓ Speed comes mostly from the microarchitecture; the same ISA can be implemented slowly or very fast.
  • Missing instructions make a machine less capable.
    ✓ Anything computable can be built from a small set; missing instructions cost speed or code size, not capability.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 3

An ISA has a 6-bit opcode field. At most how many different operations can it encode?

operations

Practice 4 · a fresh version every time

TV-16 instructions are 16 bits: opcode = bits 15–12, rd = bits 11–9, rs = bits 8–6, imm = bits 5–0. The word is 0x67B2. What is the rs field, in decimal?

Practice 5

On the 4-bit Nibble machine, A = 9 and M1 = 8. After ADD 1, what does A hold?

8.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.

Open BUILD 008: Create a Virtual Computer →

9.Reflect

Concepts: Instruction set architecture · Inside a microcontroller