TINY-8r00r10r20r30PC0LDI LD ST MOVADD SUB AND OR XOR ADDIJMP JZ JNZ HALTIN OUTbyte 0byte 1b7ob6ob5ob4o1LDI r0, 22LDI r1, 33ADD r0, r14OUT r05LDI r2, 36LDI r3, 17loop:8SUB r2, r39JNZ loop10HALTb3db2db1sb0sb7ib6ib5ib4ib3ib2ib1ib0i0123456789101112131415161710025100D00C
Back: the TINY-8 CPU, its registers and its list of 16 instructionsMiddle: one instruction as bits (opcode, d, s, imm8); front: assembly and memoryTokens: an instruction, its two bytes, and fetched byte pairs on their way to the CPUAt the back, the TINY-8 CPU with its registers, and the card of its 16 instructions. In the middle, one 2-byte instruction as 16 bit cells: opcode, d, s and imm8. In front, the assembly program and 18 bytes of memory. Each assembly line becomes two bytes: its bits appear on the cells and the bytes hop into memory. Running the program, each byte pair travels from memory through the cells (decode) to the CPU, and the registers change. TINY-8 is a teaching CPU made for this course, with every instruction exactly 2 bytes. Real 8-bit CPUs were less tidy: the MOS 6502, for example, used instructions 1 to 3 bytes long.

The instruction set

  1. An instruction set is the list of commands a CPU understands, and the exact pattern of bits that stands for each one. A program for this CPU can only use these commands. Meet TINY-8, the course's teaching CPU.

Assembly to machine code

Running, and real CPUs

What happens

;; step 1/11 · isa
instruction set   the commands a CPU understands
                  + the bit pattern (encoding) of each one
TINY-8            16 commands, 2 bytes each
  move  LDI LD ST MOV
  math  ADD SUB AND OR XOR ADDI
  jump  JMP JZ JNZ HALT
  I/O   IN OUT

TINY-8 is a teaching CPU made for this course, with every instruction exactly 2 bytes. Real 8-bit CPUs were less tidy: the MOS 6502, for example, used instructions 1 to 3 bytes long. 0x marks a hexadecimal (base-16) number. Each hex digit stands for 4 bits, so one byte is two digits, from 0x00 to 0xFF (0 to 255).