Lesson 48 of 48 advanced

Capstone: Trace, Explain, and Present a Full Interfaced System

The Final Challenge — Master the Complete Picture

Open interactive version (quiz + challenge)

Real-world analogy

This capstone is like a final pilot check-ride. You have learned every instrument in the cockpit individually — altimeter (registers), compass (flags), throttle (control signals), radio (serial), autopilot (interrupts). Now you must fly the complete airplane: take off (reset and boot), navigate (execute instructions), communicate with the tower (I/O), handle emergencies (interrupts), and land safely (produce correct output). The examiner watches every move and asks 'Why did you do that?' You must explain every decision, every signal, every timing detail.

What is it?

This capstone lesson brings together every concept from the entire course. You will trace complete system operations — from CPU instruction execution through address decoding, memory access, peripheral interaction, interrupt handling, and DMA transfer. You will analyze exam-style problems that combine knowledge across multiple topics. And you will practice presenting a complete system design: block diagram, memory map, decoding logic, initialization firmware, ISR code, and main application — the full skill set of a microprocessor engineer.

Real-world relevance

The ability to trace a complete system — to follow a signal from a device through an interrupt controller to the CPU, through the ISR, to a memory write, and out to a display — is exactly what embedded systems engineers do when debugging real products. When a car's ABS module fails, an engineer traces the sensor signal through the interrupt chain to find the fault. When a medical device misbehaves, engineers trace bus activity with logic analyzers. This complete-system thinking is the most valuable skill you can develop.

Key points

Code example

; =============================================
; CAPSTONE: Full System Trace Example
; =============================================
;
; Scenario: User presses key '5' on keyboard.
; Trace the COMPLETE path through the system.
;
; === PHASE 1: Key Detection ===
;
; Main loop executes: IN AL, 81h (read 8255 Port B)
;
; CPU bus cycle:
;   Address bus = 0081h
;   M/IO = 0 (I/O cycle)
;   I/O decoder: A7=1,A6=0,A5=0 → Y4 → CS_8255
;   8255: A1=0, A0=1 → Port B selected
;   CPU asserts RD
;   8255 puts Port B data on D0-D7
;   CPU reads into AL: 11011111 → column 5 active
;
; === PHASE 2: Display Update ===
;
; Code: MOV AL, [SEG_TABLE + 5]
;   CPU reads address 0000:SEG_TBL+5 from RAM
;   CS_RAM active (memory, low address)
;   AL = 6Dh (pattern for '5')
;
; Code: OUT 80h, AL
;   Address bus = 0080h, M/IO = 0
;   CS_8255 active, A1=0, A0=0 → Port A
;   CPU asserts WR, 8255 latches 6Dh
;   Seven-segment shows '5'
;
; === PHASE 3: Serial Logging ===
;
; Code: OUT 60h, AL (send '5' via 8251)
;   Address bus = 0060h, M/IO = 0
;   CS_8251 active
;   8251 serializes byte: START-10100110-STOP
;   TxD line sends at 9600 baud
;
; === PHASE 4: Timer Interrupt ===
;
; Meanwhile, 8254 Counter 0 reaches 0
;   OUT0 → 8259 IR0 → INTR asserted
;   CPU: INTA pulse 1 → ISR bit set
;   CPU: INTA pulse 2 → vector 08h received
;   CPU: reads IVT[08h] → jumps to TIMER_ISR
;   ISR: refreshes multiplexed display
;   ISR: MOV AL, 20h / OUT 20h, AL → EOI
;   ISR: IRET → back to main loop
;
; COMPLETE TRACE: keypress → detection → display
;   → serial log → timer interrupt → display refresh
;   All chips working together! ✓

Line-by-line walkthrough

  1. 1. Title comment for the capstone full system trace
  2. 2. Separator line
  3. 3. Blank line
  4. 4. Scenario description: user presses key '5' and we trace everything
  5. 5. Blank line
  6. 6. PHASE 1: Key Detection — scanning the keyboard through 8255
  7. 7. Blank line
  8. 8. Main loop reads Port B: IN AL, 81h
  9. 9. Blank line
  10. 10. CPU places port address 0081h on the address bus
  11. 11. M/IO signal = 0 because this is an I/O instruction (IN)
  12. 12. I/O decoder analyzes: A7=1, A6=0, A5=0 maps to output Y4
  13. 13. Y4 drives CS_8255 LOW — the 8255 is selected
  14. 14. Inside the 8255: A1=0, A0=1 selects Port B register
  15. 15. CPU asserts RD (read) control signal
  16. 16. 8255 responds by placing Port B data onto D0-D7 of the data bus
  17. 17. CPU reads the data bus into AL — pattern shows column 5 is active (key pressed)
  18. 18. Blank line
  19. 19. PHASE 2: Display Update — showing the digit on seven-segment
  20. 20. Blank line
  21. 21. Code looks up segment pattern for digit 5 from table in RAM
  22. 22. CS_RAM activates (memory access, low address range)
  23. 23. AL receives 6Dh — the seven-segment pattern that displays '5'
  24. 24. Blank line
  25. 25. OUT 80h, AL sends the pattern to 8255 Port A (display port)
  26. 26. Address bus = 0080h, M/IO=0 for I/O cycle
  27. 27. CS_8255 active again, A1=0 A0=0 selects Port A
  28. 28. CPU asserts WR, 8255 latches the byte 6Dh onto Port A output pins
  29. 29. Seven-segment display lights up segments to show the digit 5
  30. 30. Blank line
  31. 31. PHASE 3: Serial Logging — send the key value over USART
  32. 32. Blank line
  33. 33. OUT 60h, AL sends the value to the 8251 data register
  34. 34. CS_8251 activates for the I/O address
  35. 35. 8251 converts the parallel byte to a serial frame
  36. 36. TxD line transmits START bit, 8 data bits, STOP bit at 9600 baud
  37. 37. Blank line
  38. 38. PHASE 4: Timer Interrupt — asynchronous periodic event
  39. 39. Blank line
  40. 40. 8254 Counter 0 has been counting down and reaches zero
  41. 41. OUT0 output pulses to 8259 IR0 input
  42. 42. 8259 sets IRR bit 0, priority resolver selects it, asserts INTR
  43. 43. CPU finishes current instruction, sees INTR with IF=1
  44. 44. First INTA pulse: 8259 sets ISR bit 0, clears IRR bit 0
  45. 45. Second INTA pulse: 8259 places vector 08h on data bus, CPU reads it
  46. 46. CPU reads IVT entry at address 0020h — gets ISR address
  47. 47. CPU pushes FLAGS, CS, IP onto stack and jumps to TIMER_ISR
  48. 48. ISR refreshes the multiplexed display (cycles through digits)
  49. 49. ISR sends EOI (20h to port 20h) to clear the 8259 ISR bit
  50. 50. IRET pops IP, CS, FLAGS — returns to main loop exactly where it left off
  51. 51. Blank line
  52. 52. Summary: complete trace from keypress through all chips back to normal execution

Spot the bug

; System ISR for timer interrupt:
;
TIMER_ISR:
  INC WORD PTR [TICK_COUNT]
  CMP WORD PTR [TICK_COUNT], 1000
  JNE TIMER_DONE
  MOV WORD PTR [TICK_COUNT], 0
  ; Send status byte via 8251
  MOV AL, 'T'
  OUT 60h, AL
TIMER_DONE:
  IRET
;
; Main code enables interrupts:
  MOV AL, 0FEh
  OUT 21h, AL           ; unmask IR0
  STI
Need a hint?
The ISR modifies memory and registers. What about preserving the interrupted program's state? Also, what critical command is missing before IRET?
Show answer
Two bugs: (1) The ISR does not save/restore registers (AX) or flags. INC and CMP modify flags, and MOV AL changes AX. The interrupted program's register values are corrupted. Fix: add PUSH AX at the start and POP AX before IRET (and PUSHF/POPF if needed). (2) There is no EOI command before IRET. Without 'MOV AL, 20h / OUT 20h, AL', the 8259's ISR bit stays set, blocking all future timer interrupts after the first one. Fix: add EOI before IRET.

Explain like I'm 5

Imagine you built the world's most amazing Rube Goldberg machine — a ball rolls down a ramp, hits a lever, the lever rings a bell, the bell wakes up a hamster, the hamster runs on a wheel, the wheel powers a light. The capstone is like showing your machine to the whole class and explaining: 'The ball starts HERE because of gravity, the lever turns because of THIS angle, the bell rings because of THIS force, the hamster wakes because of THIS sound.' You trace every step and explain WHY it works. If you can do that for a whole microprocessor system — from key press to display to serial output to interrupt — you have truly mastered the machine beneath the software!

Fun fact

The skills you have built in this course — understanding registers, memory maps, bus timing, interrupts, and I/O interfacing — are essentially the same skills needed to reverse-engineer any electronic device. Security researchers use exactly these trace techniques to analyze unknown chips, find vulnerabilities in IoT devices, and understand how proprietary hardware works. The U.S. and global semiconductor industries have a massive shortage of engineers who understand hardware at this level — your knowledge is genuinely rare and valuable.

Hands-on challenge

Complete capstone challenge: Given an 8086 system with ROM (F0000-FFFFF), RAM (00000-0FFFF), 8255 (port C0-C3h), 8254 (port 40-43h), 8259 (port 20-21h), and 8251 (port A0-A1h): (1) Draw the complete block diagram with all bus connections. (2) Derive every chip select equation. (3) Write the full initialization code. (4) Write a timer ISR that increments a counter and sends its value via serial every 1000 interrupts. (5) Trace the execution of one complete timer interrupt cycle, listing every signal change in order.

More resources

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