Ben Eater
Hardwiring the microprocessor's floating data lines to the 0xEA NOP instruction prevents erratic executions, allowing the chip to complete its seven-cycle reset and advance sequentially through memory as a free-running counter.
AI-assisted summary of “Hello, world” from scratch on a 6502 — Part 1 — original source. Check the original for full context.
Source published:
Key ideas
- Ben Eater initiates a bare-metal 6502 computer build to ultimately display 'Hello, world', choosing the modern static W65C02 microprocessor over vintage dynamic variants to allow single-stepping down to 0 Hz without losing internal register state. (0:00)
- An Arduino Mega is deployed as an economical 50+ channel logic analyzer, synchronized to the 6502's clock via a hardware interrupt to sample and decode address, data, and R/W lines on every cycle. (6:55)
- Floating data pins caused erratic execution until tied with 1 kΩ pull-up/pull-down resistors to 0xEA, providing default opcodes during reads while safely preventing short circuits during processor write cycles. (17:49)
- Stepping through the 7-cycle hardware reset sequence reveals the processor reading the reset vector at $FFFC/$FFFD to set the program counter to $EAEA, subsequently executing NOP instructions in two clock cycles each in a classic free-run loop. (21:12)
Detailed notes
## Background Published on YouTube by Ben Eater on September 14, 2019, this video kicks off a tutorial series on computer architecture where he builds and programs a basic computer from bare silicon using the classic 6502 microprocessor. The series is designed to teach how computers work at the lowest hardware level, progressing step by step toward displaying 'Hello, world' on a physical screen.
## TL;DR Ben Eater seats a modern static W65C02 microprocessor onto a breadboard, wiring its power, control lines, and an adjustable 555-timer clock circuit. To observe the processor's internal state without an expensive logic analyzer, he configures an Arduino Mega to read the address, data, and read/write lines synchronously on rising clock edges and print formatted hexadecimal values over serial. After discovering that floating data pins cause erratic reads and writes, he uses 1 kΩ resistors to hardwire the data bus to hexadecimal $EA, the opcode for NOP (no operation). Stepping through clock pulses manually, he demonstrates the CPU's seven-cycle reset sequence, watches it fetch the reset vector from memory locations $FFFC and $FFFD, and observes the processor stabilize into a predictable free-running counter loop.
## Atmosphere & style The presentation carries the calm, methodical ambiance of a hands-on laboratory workbench, driven by Eater's clear, patient cadence and unhurried pedagogical style. The viewer experiences the tactile intimacy of wiring raw integrated circuits alongside the intellectual tension of troubleshooting erratic floating pins. When the chaotic, flickering bus output suddenly snaps into an orderly, sequential hexadecimal count, the transition delivers a quietly thrilling moment of technical satisfaction and hardware clarity.
## Bulletin - [00:00](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=0s) Ben Eater initiates a bare-metal 6502 computer build to ultimately display 'Hello, world', choosing the modern static W65C02 microprocessor over vintage dynamic variants to allow single-stepping down to 0 Hz without losing internal register state. - [06:55](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=415s) An Arduino Mega is deployed as an economical 50+ channel logic analyzer, synchronized to the 6502's clock via a hardware interrupt to sample and decode address, data, and R/W lines on every cycle. - [17:49](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1069s) Floating data pins caused erratic execution until tied with 1 kΩ pull-up/pull-down resistors to 0xEA, providing default opcodes during reads while safely preventing short circuits during processor write cycles. - [21:12](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1272s) Stepping through the 7-cycle hardware reset sequence reveals the processor reading the reset vector at $FFFC/$FFFD to set the program counter to $EAEA, subsequently executing NOP instructions in two clock cycles each in a classic free-run loop.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=0s) Starting a computer from bare microprocessor hardware requires directly managing buses, clock signals, and control lines that high-level operating systems and runtimes usually abstract away. - [03:56](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=236s) The project uses the modern CMOS W65C02 rather than the vintage NMOS 6502 because its static core retains register states indefinitely when the clock is stopped or slowed down. - [01:11](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=71s) Active microprocessor operation requires tying control inputs like RDY, IRQB, NMIB, and BE high to prevent halting or spurious interrupt states. - [03:56](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=236s) A custom 555-timer clock circuit enables variable frequency and debounced pushbutton single-stepping, which is crucial for manually observing machine cycles. - [06:55](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=415s) Discrete LEDs provide immediate bus activity feedback, but quickly become impractical and visually unreadable when scaling up to monitor wide 16-bit address and 8-bit data buses simultaneously. - [06:55](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=415s) The Arduino Mega acts as a cost-effective logic analyzer, offering over 50 digital I/O lines to decode and format all bus signals simultaneously over a serial connection. - [09:48](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=588s) Connecting the CPU clock line to an Arduino hardware interrupt pin (pin 2) synchronizes data capture to the rising edge, preventing asynchronous read polling artifacts. - [16:18](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=978s) Tracking the R/W control line is essential to determine whether data on the bus represents an instruction/operand read by the CPU or an active write operation to memory. - [17:49](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1069s) Floating bus lines act as high-impedance antennas that read random electrical noise, destabilizing the processor's internal state machine. - [19:20](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1160s) Using 1 kΩ resistors to hardwire the data bus establishes default logic levels during reads while limiting current to safe levels if the processor drives conflicting voltages during writes. - [19:20](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1160s) Hardwiring the data lines to binary 1110 1010 ($EA) stabilizes the CPU, forcing it into continuous read mode and sequential address incrementing. - [21:12](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1272s) Upon exiting reset after a seven-cycle internal initialization sequence, the 6502 fetches its starting program counter from the 16-bit reset vector at memory locations $FFFC and $FFFD. - [23:35](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1415s) The hardwired opcode $EA decodes to NOP (No Operation), which uses implied addressing and takes exactly two clock cycles per instruction to execute. - [23:35](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1415s) Continuously feeding NOP instructions creates a classic 'free-run' harness where the program counter sequentially traverses the entire 64 KB address space. - [26:02](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1562s) Building beyond the free-run verification stage requires adding programmable ROM (EEPROM) and RAM to support real software execution and peripheral display output.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=0s) Starting from Bare Silicon: The 6502 Microprocessor
Most programming tutorials kick off by writing a trivial program that prints "Hello, world" to a terminal. While high-level languages like Python make this trivial by handling memory management, operating system calls, and display drivers under the hood, building up to that output from bare metal poses an entirely different challenge. Ben Eater introduces the central question of the build: “Well, it seems like every programming tutorial starts out having you write a simple program that just prints out hello world and it's usually a pretty simple starting point because the programming language in this case Python and everything gets built on top of does a lot of the work but what if we don't have any of that what if we just start with a microprocessor?”
The hardware at the center of the project is the classic 6502 microprocessor. Holding up a vintage chip, Eater notes its date code reveals it was manufactured in the third week of 1989, though the underlying architecture traces all the way back to 1975. Throughout the late 1970s and 1980s, variants of the 6502 powered seminal personal computers and gaming consoles like the Apple II, Commodore 64, and Nintendo Entertainment System. Despite being a 44-year-old design, brand-new versions of the chip remain in production today. Eater selects the modern static variant, the W65C02, accompanied by a concise, roughly 30-page datasheet that documents its functional pinout and electrical characteristics.
```mermaid flowchart LR accTitle: High-Level Abstraction vs Bare Hardware accDescr: Contrast between high-level Python software and bare 6502 microprocessor hardware.
subgraph SW["High-Level Abstraction"] PY["Python Print Statement"] --> OS["OS / Runtime Engine"] OS --> HW_LAYER["Display Drivers & Memory"] end
subgraph HW["Bare Metal Target"] CPU["W65C02 Microprocessor"] --> BUS["Address & Data Buses"] BUS --> SCREEN["Direct Hardware Display"] end ```
[01:11](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=71s) Wiring Power, Control Lines, and Busses
Eater places the 40-pin dual in-line package (DIP) chip onto a solderless breadboard to configure its primary pins. The electrical foundation begins with the power rails: pin 8 ($V_{DD}$) connects to the $+5\text{ V}$ positive supply rail, while pin 21 ($V_{SS}$) ties to the system ground rail. However, merely providing five volts leaves the processor idle; active operation requires conditioning its dedicated input and control pins according to the datasheet specifications:
```mermaid flowchart TD accTitle: 6502 Breadboard Initial Pin Hookups accDescr: Mapping of 6502 processor pin connections to power, ground, and control logic.
subgraph Power["Power Connections"] VDD["Pin 8 (VDD)"] --> Rail5V["+5V Rail"] VSS["Pin 21 (VSS)"] --> RailGND["Ground Rail"] end
subgraph TiedHigh["Inputs Tied High (+5V)"] RDY["Pin 2 (RDY)"] --> Rail5V IRQB["Pin 4 (IRQB)"] --> Rail5V NMIB["Pin 6 (NMIB)"] --> Rail5V BE["Pin 36 (BE)"] --> Rail5V SO["Pin 38 (SO)"] --> Rail5V end
subgraph OpenOutputs["Outputs Left Unconnected"] VPB["Pin 1 (VPB)"] PHI1O["Pin 3 (PHI1O)"] MLB["Pin 5 (MLB)"] SYNC["Pin 7 (SYNC)"] PHI2O["Pin 39 (PHI2O)"] ADDR["Pins 9-20, 22-25 (A0-A15)"] end ```
- **Power**: Pin 8 ($V_{DD}$) connects to $+5\text{ V}$; Pin 21 ($V_{SS}$) connects to ground. - **Ready (RDY, Pin 2)**: An active-high input that determines whether the processor executes instructions or halts. Tied directly to $+5\text{ V}$ to keep the core running continuously. - **Interrupt Requests ($\overline{\text{IRQ}}$, Pin 4 and $\overline{\text{NMI}}$, Pin 6)**: Active-low interrupt inputs. Tied directly to $+5\text{ V}$ to prevent spurious interrupts from firing. - **Bus Enable (BE, Pin 36)**: An active-high input required for the CPU to assert signals onto both the address and data busses. Tied directly to $+5\text{ V}$. - **Set Overflow (SO, Pin 38)**: An input line intended for conditional branching hardware. The datasheet recommends tying it high when unused. - **Unconnected Outputs**: Pin 1 ($\overline{\text{VP}}$ / Vector Pull), Pin 3 ($\Phi_{1\text{O}}$), Pin 5 ($\overline{\text{ML}}$ / Memory Lock), Pin 7 ($\text{SYNC}$), Pin 39 ($\Phi_{2\text{O}}$), and Pin 35 ($\text{NC}$ / No Connect) remain open. - **Address Bus ($A_0$–$A_{15}$)**: Across pins 9–20 and 22–25, these 16 pins form the unidirectional address outputs, initially left unconnected. - **Data Bus ($D_0$–$D_7$) and Read/Write ($R/\overline{W}$)**: Data bus pins 26–33 are bidirectional. Pin 34 ($R/\overline{W}$) indicates transfer direction: logic high means the CPU is reading (data bus configured as inputs), whereas logic low signifies a memory write (data bus configured as outputs). Both are temporarily left floating.
[03:56](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=236s) Clocking Architecture: Static Core vs. Dynamic Design
Any microprocessor requires a stable clock pulse to drive internal state machines and sequential execution. Original 6502 processors typically operated on a $1\text{ MHz}$ clock, whereas the modern W65C02 supports operating frequencies up to $17\text{ MHz}$. While a standard crystal oscillator module (such as a $10\text{ MHz}$ canned can oscillator) can generate clean clock inputs by simply connecting power and ground, high-speed clocks obscure internal operations from visual inspection.
Instead of a high-speed crystal, Eater utilizes a custom 555-timer-based clock module from an earlier breadboard computer build. This circuit features adjustable frequency control (allowing the user to speed up or slow down clock cycles at will), a halt toggle switch, and a debounced push button for single-stepping individual clock pulses.
Deploying this slow, single-steppable clock highlights the critical architectural distinction between the vintage NMOS 6502 and the modern CMOS W65C02. Eater explains: “And this is where it's actually really important that I'm using the modern static version of the 6502 because the datasheet here says that phi2 can be held in either the high or low state and it'll preserve the contents of internal registers and that's actually not the case with the original 6502.” Dynamic NMOS designs rely on internal capacitive charge storage that rapidly discharges if the clock speed drops below a minimum threshold (around $100\text{ kHz}$), destroying register state. In contrast, the modern W65C02 uses static logic cells that maintain their internal state indefinitely, even when the clock input at Pin 37 ($\Phi_2$) is held completely stationary in either a logic high or logic low state.
To control startup, Pin 40 ($\overline{\text{RES}}$ / Reset) requires active pull-up conditioning. Eater attaches a $1\text{ k}\Omega$ pull-up resistor from Pin 40 to $+5\text{ V}$, holding the processor in operational mode during normal conditions. A momentary tactile push button is wired between Pin 40 and ground; pressing the switch shunts Pin 40 directly to ground, asserting a hard hardware reset.
```mermaid flowchart LR accTitle: Reset and Clock Input Circuits accDescr: Schematic implementation of the 555-timer clock input and manual reset switch.
subgraph ClockGen["Clock Subsystem"] TMR["555 Timer Module"] -->|"Variable / Step"| PHI2["Pin 37 (PHI2)"] end
subgraph ResetCirc["Reset Subsystem"] VCC["+5V"] --- R1["1k Resistor"] R1 --- RES["Pin 40 (RES)"] SW["Push Button"] --- RES SW --- GND["Ground"] end ```
[06:55](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=415s) Diagnosing Activity: LEDs vs. Logic Analyzers vs. Arduino
With $+5\text{ V}$ power supplied, the variable clock running, and the manual reset button cycled, the processor begins stepping through its internal startup sequence. However, with the address and data busses floating in midair, there is no immediate visual indication of what the microprocessor is doing. To observe pin activity, Eater installs five discrete LEDs on the breadboard, wiring their anodes to address lines $A_0$ through $A_4$ and their cathodes to ground through current-limiting $220\ \Omega$ resistors.
Pulsing the clock produces flickering light patterns across the five LEDs, confirming that internal state changes are toggling the bus pins. However, monitoring only five bits provides an incomplete, cryptic picture. Monitoring all sixteen address lines, eight data bus lines, and multiple control pins simultaneously would require dozens of LEDs, cluttering the breadboard and making chronological analysis virtually impossible to track by eye.
```mermaid flowchart TD accTitle: Diagnostic Tool Tradeoffs accDescr: Comparison of breadboard diagnostic methods highlighting the Arduino Mega.
LED["Breadboard LEDs"] -->|"Pros: Simple\nCons: Limited pins, hard to read"| LIMIT1["Poor Visibility"] LA["Hardware Logic Analyzer"] -->|"Pros: MHz sampling, waveforms\nCons: Only 16 channels, overkill for slow clock"| LIMIT2["Channel Constrained"] ARD["Arduino Mega 2560"] -->|"Pros: 50+ digital I/O, cheap, direct decode\nCons: Low sample rate (acceptable here)"| BEST["Optimal Monitoring Tool"] ```
While a dedicated 16-channel logic analyzer excels at capturing high-frequency digital waveforms over time, Eater points out that it presents practical limitations for this setup: it is channel-constrained, and its high sampling rates are unnecessary when single-stepping or running the clock at sub-kilohertz speeds. Eater argues for a simpler approach: “I think a much better and definitely less expensive tool is actually just an Arduino because if we want to monitor what these address lines are doing we could just hook them up to inputs on the Arduino and have the Arduino just read whatever is on each of these pins and you know, especially something like this Arduino Mega it's got, you know, something like 50 digital inputs so way more than the 16 inputs that we have on nice logic analyzer like this.” The Arduino Mega can sample all address lines, data lines, and control signals on every clock pulse, formatting and printing the machine state directly to a serial terminal.
[09:04](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=544s) Connecting the Address Bus to an Arduino Mega
Ben Eater decides to clear away the bulky logic analyzer probes and the breadboard LEDs to replace them with an Arduino Mega. Because the 6502 microprocessor has a 16-bit address bus, an Arduino Mega provides more than enough general-purpose digital I/O pins to monitor every address line simultaneously. He attaches a 16-conductor ribbon cable running from the processor's address pins (A0 through A15) straight into a bank of Arduino digital inputs, remembering to connect a common ground between the two boards. Ben Eater summarizes the setup: “So just like the logic analyzer the Arduino can then keep track of you know, what each address line is doing.”
```mermaid flowchart LR accTitle: Arduino Mega Bus Monitor Setup accDescr: Diagram showing the 6502 address and clock lines hooked up to the digital pins of an Arduino Mega. subgraph CPU["W65C02 Microprocessor"] A["Address Lines (A15–A0)"] CLK["Clock Line (PHI2)"] end subgraph Arduino["Arduino Mega"] D_PINS["Pins 22–52 (Even)"] INT_PIN["Pin 2 (Interrupt)"] UART["Serial Monitor (57,600 baud)"] end A -->|"16-pin ribbon cable"| D_PINS CLK -->|"Interrupt trigger"| INT_PIN D_PINS --> UART INT_PIN --> UART ```
In the Arduino IDE, Ben writes a sketch defining the specific pins used for the address bus, starting with address bit A15 mapped to pin 22 and descending through the even-numbered header pins down to A0 on pin 52. In the `setup()` function, a `for` loop iterates through all 16 pins to configure their `pinMode` as `INPUT`, while initializing serial communication at a standard baud rate of 57,600. In the `loop()` function, the code reads each pin in order with `digitalRead()`, checks whether the boolean returned is true or false to print a literal `1` or `0` to the serial monitor, and appends a newline after printing all sixteen bits.
- Address line mapping: Pin 22 (A15) down through pin 52 (A0). - Serial speed: Configured to 57,600 baud. - Initial read implementation: Continuous polling inside `loop()`, spitting raw 16-bit binary strings across the terminal.
[09:48](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=588s) Reading the Bus and Adding Clock Synchronization
When Ben uploads the sketch and opens the serial monitor, binary numbers immediately begin streaming across the screen. However, interpreting this raw stream proves difficult because the values scroll uncontrollably. Ben notes: “It looks like it's just kind of spewing a bunch of ones and zeros that are changing, you know maybe on every clock pulse, or maybe it's every other clock pulse.” Because the Arduino's `loop()` runs asynchronously at its own processing rate, it reads the address pins at random intervals relative to the 6502's clock cycles, making it impossible to correlate bus states with specific instructions.
To fix this, Ben takes advantage of the Arduino's remaining digital I/O pins by routing the 6502 clock signal to digital pin 2. Digital pin 2 on the ATmega board supports hardware interrupts. Rather than reading the clock inside the standard loop, Ben invokes `attachInterrupt()` in `setup()` to bind an interrupt handler function named `onClock` to pin 2, configuring it to trigger specifically on the rising edge (`RISING`) when the clock transitions from low to high.
Ben empties out `loop()` entirely and migrates the bus-reading code into `onClock()`. Ben explains the reasoning: “The only time we do anything is when we get a clock pulse and then we just print the address once so let's give this a try.” When the updated sketch runs, the serial monitor prints exactly one line of data per clock pulse. Halting the clock module cleanly freezes the serial output, allowing Ben to pulse the clock manually and single-step through cycles one by one.
- Clock input: Connected directly to Arduino digital pin 2. - Interrupt trigger: Configured for the rising edge of the clock signal (`RISING`). - Behavior: The Arduino loop does nothing; bus state is printed strictly once per clock tick, enabling precise manual single-stepping.
[13:23](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=803s) Monitoring the Data Bus and Formatting Hex Output
While stepping through single cycles provides stable readings, raw 16-bit binary remains tedious to decipher. To understand what the processor is actually attempting to execute, Ben decides to inspect the 8-bit data bus (D7 down to D0) alongside the address bus. He connects eight additional jumper wires from the processor's data lines to pins 39 through 53 (the odd-numbered pins) on the Arduino Mega header, then declares these pins in the sketch and sets their `pinMode` to `INPUT` during setup.
```mermaid flowchart TD accTitle: Bus Processing and Formatting Flow accDescr: Flowchart illustrating how address and data pins are read, bit-shifted into numerical values, and formatted as hex. Start["Rising Clock Edge (onClock Interrupt)"] --> ReadAddr["Read Pins 22–52 (16 bits)"] ReadAddr --> ShiftAddr["Shift Left & Accumulate into 16-bit unsigned int"] ShiftAddr --> ReadData["Read Pins 39–53 (8 bits)"] ReadData --> ShiftData["Shift Left & Accumulate into 8-bit unsigned int"] ShiftData --> ReadRW["Read Pin 3 (R/W Line)"] ReadRW --> Format["sprintf(output, '%04x %c %02x', addr, r_w, data)"] Format --> Print["Serial.println(output)"] ```
Ben also addresses the readability of the bus values. Ben Eater remarks: “The other thing I can do here to make it easier to sort of interpret what's going on is instead of just printing out the binary ones and zeros like we are we could print the values in decimal or actually in hexadecimal.” Instead of printing characters directly during the bit-reading loops, he initializes an unsigned integer variable to zero, shifts it left by one bit on every iteration (`address = (address << 1) + bit`), and adds the current bit. By repeating this pattern for both the 16 address bits and the 8 data bits, he converts the bus signals into clean numeric values.
Using `sprintf()`, Ben formats the accumulated values into a 15-character buffer, displaying the address as a 4-digit hexadecimal number (`%04x`) and the data as a 2-digit hexadecimal number (`%02x`).
- Data bus mapping: Pins 39 through 53 (odd numbers) monitor D7 down through D0. - Numerical conversion: Bit-shifting accumulation converts 16 address bits into an unsigned 16-bit integer and 8 data bits into an unsigned byte. - String output: `sprintf` formats the values into a compact hex readout.
[16:18](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=978s) Tracking the Read/Write Signal and Interpreting Bus Traffic
Ben points out that knowing the address and data values is still not enough to understand the processor's intent because the data bus is bidirectional. He introduces the processor's Read/Write ($R/\bar{W}$) control signal. Ben Eater explains how it operates: “So this read/write pin is high then it means the processor is reading from the data bus and if this is low then it means it's writing to the data bus.” Tracking this line is essential for determining whether the CPU expects external memory to supply an opcode or operand, or whether the CPU is driving data out to store it.
Ben connects the $R/\bar{W}$ pin to digital pin 3 on the Arduino, defines it in code, and sets it as an input in `setup()`. In `onClock()`, the sketch performs a `digitalRead()` on pin 3 and adds an indicator character to the serial output string: printing an `r` when the line is high (reading) and a `W` when the line is low (writing). After catching a minor syntax error—a missing comma in his `sprintf()` arguments—Ben re-uploads the sketch and starts the clock.
``` Expected Serial Output Format: [Address (hex)] [R/W] [Data (hex)] 04a2 r ea 04a3 r ea 01fd W 04 ```
The serial monitor springs to life with formatted output displaying addresses, read/write states, and data values. Even with this clean format, the processor's behavior appears chaotic: addresses leap across the memory map unpredictably, data values fluctuate wildly, and the chip alternates erratically between read and write cycles.
- $R/\bar{W}$ line mapping: Routed to Arduino pin 3. - Output notation: `r` indicates the processor is reading data; `W` indicates the processor is writing data.
[17:49](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1069s) Floating Inputs and Tying the Data Bus with Resistors
Ben analyzes why the processor behaves so erratically despite the monitoring code functioning properly. He points out that while the Arduino is reading the data lines, nothing on the breadboard is actually driving them during read cycles. The data bus pins are floating, disconnected from any memory chip or peripheral. Whenever the 6502 flags an `r` cycle to read an instruction byte from memory, it reads electrical noise and floating capacitance. Ben Eater observes: “So if the processor is just kind of reading garbage whenever it reads from those data pins, you know I guess I would sort of expect it to behave kind of randomly.”
To establish predictable behavior without wiring in a full ROM chip yet, Ben decides to hardwire the data pins to a known, constant bit pattern. To do this safely, he ties each of the eight data pins to either +5 volts (logic high) or ground (logic low) using 1 kΩ current-limiting resistors rather than direct wire jumpers.
The 1 kΩ resistors serve an important electrical purpose: when the 6502 is reading, the processor's high-impedance inputs easily read the weak logic levels pulled through the resistors as valid ones and zeros. However, when the 6502 occasionally enters a write state (`W`) and actively drives its own output voltages onto the data bus, the processor's internal drivers easily override the weak resistor pulls without causing a short circuit between power and ground.
- Cause of errant execution: The data bus is floating, feeding random garbage opcodes to the CPU during read cycles. - Temporary solution: Hardwire each data bus line to a fixed logic level (5V or GND) via 1 kΩ resistors. - Electrical protection: 1 kΩ series resistors provide a default logic level during CPU reads, while allowing the CPU's active output drivers to override the line safely during write cycles without drawing excessive current.
[19:20](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1160s) Hardwiring an Opcode: Setting Up 0xEA on the Data Bus
To prevent the processor from driving illegal states or floating into erratic behavior, Ben connects a series of resistors to the data bus pins. In the worst-case scenario where the processor outputs an opposite logic level, there would only be a five-volt potential difference across each resistor, safely limiting current. As Ben explains: “In other words these resistors that I'm putting that I'm adding here are just kind of setting a default value, but you know if the processor outputs something different then you know, no big deal.” He ties each resistor to either ground or 5 volts in a specific pattern, presenting the binary value `1110 1010`—hexadecimal `$EA`—to the data bus pins.
```mermaid flowchart TD accTitle: 6502 Reset and Free-Run Execution Flow accDescr: Flowchart showing how the 6502 initializes across seven cycles, fetches the reset vector from memory, and repeatedly executes NOP instructions.
subgraph ResetPhase ["Hardware Reset"] R1["Reset line pulsed low"] --> R2["Internal reset sequence<br/>(7 clock cycles)"] end
subgraph VectorFetch ["Reset Vector Fetch"] R2 --> V1["Read low byte from $FFFC<br/>(Gets $EA)"] V1 --> V2["Read high byte from $FFFD<br/>(Gets $EA)"] V2 --> V3["Load Program Counter<br/>PC = $EAEA"] end
subgraph Execution ["Execution Loop"] V3 --> E1["Fetch opcode at PC ($EAEA)<br/>(Reads $EA / NOP)"] E1 --> E2["Execute NOP<br/>(Takes 2 clock cycles)"] E2 --> E3["Increment PC<br/>PC = PC + 1"] E3 --> E1 end ```
Once the bus is tied off and powered up, the processor’s erratic output vanishes immediately. The Arduino serial monitor shows that the 6502 is now exclusively performing read operations rather than alternating unpredictably between reads and writes. On every read cycle, the data byte returned is `$EA`. Furthermore, the address bus stops jumping randomly across the address space and begins incrementing sequentially: `... FFFE, FFFF, 0000, 0001, 0002...` through memory in an orderly hexadecimal progression. Simply establishing a steady, predictable input on the data bus stabilizes the processor's internal state machine.
- The hardwired data bus pattern is binary `1110 1010`, corresponding to hexadecimal `$EA`. - The pull-up and pull-down resistors act as default bus terminators without short-circuiting outputs if the processor drives the bus. - With data lines defined, the read/write line (`R/W`) stays high (read mode) instead of thrashing, and the address bus behaves as a continuous sequential counter.
---
[21:12](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1272s) Stepping Through the Reset Sequence and the Reset Vector
When Ben pushes the onboard reset button, the address bus momentarily shifts before settling back into its counting routine. Consulting the Western Design Center W65C02S datasheet, he reviews the exact behavior of the reset pin: “It says when a positive edge is detected, there'll be a reset sequence lasting seven clock cycles.” To observe this directly, Ben holds down the reset switch, halts the automated clock module, clears the Arduino serial monitor, and manually single-steps the clock using the pushbutton.
Advancing the clock seven single pulses completes the seven internal reset cycles, during which the processor carries out housekeeping tasks. On the eighth clock cycle, the chip places address `$FFFC` onto the address bus and signals a read. The datasheet specifies that upon exiting reset, the program counter register is populated from the 16-bit reset vector located at addresses `$FFFC` (holding the low byte) and `$FFFD` (holding the high byte). Advancing the clock once more places `$FFFD` on the address bus. Because Ben has hardwired the data lines to `$EA`, the CPU reads `$EA` for the low byte at `$FFFC` and another `$EA` for the high byte at `$FFFD`. Consequently, the internal program counter is loaded with the start address `$EAEA`.
- Reset initialization on the 6502 requires exactly seven clock cycles following a positive edge. - Memory locations `$FFFC` and `$FFFD` form the 16-bit reset vector defining the execution entry point. - Because the hardwired bus returns `$EA` on every access, the processor loads the low byte `$EA` and high byte `$EA`, setting `PC = $EAEA`.
---
[23:35](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1415s) Fetching and Executing NOP: The Free-Running Counter
With the reset vector loaded, the processor is primed to begin fetching instructions. Stepping the clock one additional cycle reveals that the address lines immediately update to `$EAEA`, exactly matching the loaded program counter value. The processor outputs a read request to fetch its first instruction from this location and reads `$EA` from the bus resistors. It must now decode and execute `$EA`.
Ben looks up `$EA` in the datasheet's opcode matrix: locating row `E` and column `A` reveals that `$EA` corresponds to the `NOP` instruction—"no operation." As Ben observes: “So basically the processor is going to do nothing.” Stepping the clock again increments the address to `$EAEB`, where the CPU reads another `$EA`, executing another `NOP`. He notes an important architectural timing detail: it takes two full clock cycles for each address increment to occur. Cross-referencing the datasheet's opcode matrix reveals a small subscript `i` next to `NOP`, denoting the implied addressing mode. The addressing mode specification confirms that instructions utilizing implied addressing require two clock cycles to complete. Running the clock continuously produces a classic "free-run" harness where the CPU loops forever, taking two clock cycles per instruction to do nothing while steadily counting across the entire 64 KB address space.
- Opcode `$EA` decodes to `NOP` (No Operation) on the 6502 microprocessor. - `NOP` uses implied addressing (marked by an `i` in the matrix) and requires exactly two clock cycles per instruction execution. - In this open-bus state, the CPU operates as an automated 16-bit counter, incrementing its program counter across memory without branching or halting.
---
[26:02](https://www.youtube.com/watch?v=LnzuMJLZRdU&t=1562s) Looking Ahead: Kits, EEPROMs, and Future Plans
While hardwiring the data bus proves that the microprocessor can reset, fetch, decode, and execute instructions, Ben points out that a machine forced to execute nothing but hardwired `NOP`s is not yet a functional computer. In the upcoming video, he plans to replace the resistor network with a programmable ROM chip so that the processor can fetch real instructions from distinct memory addresses, paving the way toward a functional "Hello, World" program.
Ben announces that he has assembled a full hardware kit for viewers wanting to build along with the project, available through his website at `eater.net/6502`. The kit includes the 6502 CPU along with RAM, ROM, an LCD screen, and input buttons, leading toward building an interactive assembly language game. He emphasizes that builders will also need an external EEPROM programmer, along with the 555-timer clock module kit and the Arduino Mega used as the diagnostic bus monitor. He closes by thanking the Patreon supporters whose contributions fund these hardware build projects.
- The next stage replaces hardwired resistors with an EEPROM chip containing programmed software routines. - The project kit at `eater.net/6502` includes the 6502 microprocessor, RAM, ROM, and I/O components intended to support a display and an assembly language game. - Essential complementary tools not included in the primary chip kit comprise a dedicated EEPROM programmer, the custom 555-based clock module, and an Arduino Mega logic monitor.
## Mentioned Ben Eater, 6502 microprocessor, W65C02, Apple II, Commodore 64, Nintendo Entertainment System, Arduino Mega, Arduino IDE, 555 timer, Python, Western Design Center, Patreon
## Video description Learn how computers work in this series where I build and program a basic computer with the classic 6502 microprocessor. More info: https://www.eater.net/6502
Part 2: https://www.youtube.com/watch?v=yl8vPW5hydQ Part 3: https://www.youtube.com/watch?v=oO8_2JJV0B4 Part 4: https://www.youtube.com/watch?v=FY3zTUaykVo Part 5: https://www.youtube.com/watch?v=xBjQVxVxOxc Part 6: https://www.youtube.com/watch?v=i_wrxBdXTgM Part 7: https://www.youtube.com/watch?v=omI0MrTWiMU
Support these videos on Patreon: https://www.patreon.com/beneater or https://eater.net/support for other ways to support.
------------------
Social media: Website: https://www.eater.net Twitter: https://x.com/beneater Patreon: https://patreon.com/beneater Reddit: https://www.reddit.com/r/beneater
Special thanks to these supporters for making this video possible: Alex Catchpole Armin Brauns BakerStaunch Beau-James Erion Ben Ben Dyson Ben Kamens Ben Williams Bradley Pirtle Christopher Blackmon Clayton Parker Coleman Daniel Tang Dean Winger Debilu Krastas Dominic Kulmer Dušan Dželebdžić Eric Brummer Eric Dynowski Erik Broeders Eugene Bulkin fxshlein HaykH Ian Tait Ivan Sorokin JavaXP Jay Binks Jayne Gabriele Jefferson Hunt Jimmy Campbell Joel Messerli Joel Miller Jordan Scales Joshua King Justin Duch Kent Collins Manne Moquist Marcus Classon Mats Fredriksson Michael Michael Burke Michael Garland Miguel Ríos Nathan Wachholz Nicholas Moresco Onion Sniffer Paul Pluzhnikov Peter Simard Randy True Robert Butler Sachin Chitale Sergey Ten SonOfSofaman Stefan Nesinger Stephen Smithstone Steve Gorman Thomas Ballinger Vladimir Kanazir xisente Örn Arnarson
[Source](https://www.youtube.com/watch?v=LnzuMJLZRdU)