Lesson 6 of 48 beginner

Registers, ALU, and Buses

The three pillars of processor hardware — where data lives, how it's computed, and how it moves

Open interactive version (quiz + challenge)

Real-world analogy

Think of the CPU as a workshop. Registers are the workbench — small surfaces right in front of you where you keep the parts you're currently working on. The ALU is your set of tools — drills, saws, and wrenches that transform those parts. Buses are the conveyor belts connecting the workbench to the warehouse (memory) — one belt carries the address label (address bus), another carries the actual parts (data bus), and a third carries instructions like 'send' or 'receive' (control bus).

What is it?

Registers are small, fast storage locations inside the CPU that hold data being actively processed. The ALU (Arithmetic Logic Unit) is the computational engine that performs all arithmetic and logic operations. Buses are the communication highways: the address bus (20-bit, one-way) carries memory addresses, the data bus (16-bit, bidirectional) carries data values, and the control bus carries timing and command signals. Together, they form the core hardware architecture of the 8086 processor.

Real-world relevance

When you press a key on your keyboard, the data travels along a bus to an I/O port. The CPU reads it using an IN instruction — the address bus specifies the port number, the control bus signals an I/O read, and the data bus carries the key code into a register. The ALU might then compare it (is it Enter? Escape?) and a conditional jump decides what to do next. Every interaction with your computer — every click, every pixel, every network packet — passes through these registers, the ALU, and buses.

Key points

Code example

; Demonstrating registers, ALU, and buses in action
; Program: Add two numbers from memory, store result

; Setup segment
MOV AX, 1000h
MOV DS, AX         ; DS = 1000h (data segment base)

; Read two values from memory (uses address + data bus)
MOV AX, [0010h]    ; Address bus: 10000h + 0010h = 10010h
                    ; Control bus: M/IO=1, RD=0
                    ; Data bus: value at 10010h -> AX

MOV BX, [0020h]    ; Address bus: 10000h + 0020h = 10020h
                    ; Data bus: value at 10020h -> BX

; ALU performs addition (entirely inside the CPU)
ADD AX, BX         ; ALU input A: AX
                    ; ALU input B: BX
                    ; ALU output: AX = AX + BX
                    ; FLAGS updated (CF, ZF, SF, OF, PF, AF)

; Store result back to memory (uses address + data bus)
MOV [0030h], AX    ; Address bus: 10000h + 0030h = 10030h
                    ; Control bus: M/IO=1, WR=0
                    ; Data bus: AX -> memory at 10030h

HLT                ; stop execution

Line-by-line walkthrough

  1. 1. First we set up the data segment: MOV AX, 1000h / MOV DS, AX puts 1000h into DS. This tells the CPU that our data lives starting at physical address 10000h (1000h * 16).
  2. 2. MOV AX, [0010h] triggers a memory read. The address bus carries 10010h (DS*16 + 0010h). The control bus sets M/IO=1 and RD=0. Memory places the 16-bit value on the data bus, and it flows into AX.
  3. 3. MOV BX, [0020h] does the same for address 10020h. Now we have both operands in registers — fast internal storage, no bus activity needed to use them.
  4. 4. ADD AX, BX is purely internal — no bus activity! The ALU takes AX and BX as inputs, adds them, puts the result in AX, and updates all arithmetic flags (CF, ZF, SF, OF, PF, AF).
  5. 5. MOV [0030h], AX writes the result back to memory. The address bus carries 10030h, the data bus carries the value from AX (outbound this time), and the control bus asserts WR=0.
  6. 6. HLT stops the processor. Notice how even this simple program required coordination of all three buses and the ALU — that is the essence of CPU operation.

Spot the bug

; Program to read a byte from I/O port 60h (keyboard)
; and store it in memory at DS:0100h

MOV AX, 2000h
MOV DS, AX        ; DS = 2000h

IN AX, 60h        ; read from keyboard port
MOV [0100h], AX   ; store in memory

; BUG: The keyboard port returns an 8-bit value.
; What's wrong with using AX (16-bit) here?
Need a hint?
Consider what happens when you read a 16-bit value from an 8-bit I/O port. What ends up in the upper byte AH?
Show answer
Bug: The keyboard controller port 60h returns only an 8-bit scan code, but IN AX, 60h reads 16 bits — it reads port 60h into AL AND port 61h into AH (the next port). Port 61h is the PPI control register, not keyboard data! The upper byte AH will contain unrelated data from port 61h, corrupting your result. Fix: Use IN AL, 60h to read only 8 bits from the correct port, then MOV [0100h], AL to store just the key scan code. Alternatively, zero AH first (XOR AH, AH) if you need the full 16-bit MOV for alignment reasons.

Explain like I'm 5

Imagine you have a tiny desk (registers) where you keep the toy blocks you're playing with right now. You have a special tool (ALU) that can combine blocks — stacking them, swapping colors, or counting them. And you have three hallways connecting your desk to a giant toy warehouse (memory): one hallway where you yell the shelf number (address bus), one where the toy rolls back and forth (data bus), and one where you wave flags like 'send me a toy!' or 'I'm putting one back!' (control bus).

Fun fact

The 8086's registers are named after their ancestors! AX stands for 'Accumulator' (from early CPUs where one special register accumulated results), CX for 'Counter' (used with LOOP), and DX for 'Data' (used for I/O port addresses). These names stuck around — even modern x86-64 processors still have RAX, RBX, RCX, RDX, now expanded to 64 bits. The naming convention has survived over 45 years!

Hands-on challenge

Write an 8086 assembly program that demonstrates all three buses and the ALU working together. Your program should: (1) load two values from specific memory addresses into registers, (2) perform at least three different ALU operations on them (e.g., ADD, AND, SHL), (3) store results back to different memory locations. For each instruction, annotate which bus carries what signal/data. Finally, list all the FLAGS that would be set or cleared after each ALU operation.

More resources

Open interactive version (quiz + challenge) ← Back to course: Microprocessor A–Z