Foundations

Registers & Memory

Understanding registers, memory layout, and the fetch-execute cycle.

Registers

Registers are small, fast storage locations inside the CPU. The LC-3 has:

  • R0–R7: General-purpose registers. You use these for all your computations.
  • PC: The Program Counter — holds the address of the next instruction.
  • CC: Condition Codes (N, Z, P) — set automatically by certain instructions.
  • Registers are much faster than memory. Most instructions work directly with registers.

    Memory Layout

    LC-3 memory is organized as 65,536 (2^16) locations, each holding a 16-bit value:

    Address RangePurpose
    x0000–x00FFTrap vector table
    x0100–x01FFInterrupt vector table
    x0200–x2FFFOperating system
    x3000–xFDFFUser program space
    xFE00–xFFFFDevice registers (I/O)
    Your programs start at x3000 — that's why .ORIG x3000 is the standard.

    The Fetch-Execute Cycle

    Every instruction goes through these phases:

  • FETCH: Read the instruction at memory[PC], then PC = PC + 1
  • DECODE: Determine the opcode and operands
  • EVALUATE ADDRESS: Compute any memory addresses needed
  • FETCH OPERANDS: Read register/memory values
  • EXECUTE: Perform the operation
  • STORE RESULT: Write the result to a register or memory
  • The PC is incremented during FETCH, before the instruction executes. This matters for PC-relative addressing — offsets are relative to the already-incremented PC.

    Quiz

    When a PC-relative instruction at address x3005 is executing, what value does the PC hold?