The ATmega328P is the 8-bit AVR microcontroller at the heart of the Arduino Uno. This page is a browser-based teaching model (not a cycle-accurate silicon emulator): you can type a small subset of assembly, single-step or run it, and see registers, the status register (SREG), SRAM, EEPROM, and Flash (program listing) update together with a 28-pin DIP drawing where PORTB pins glow when driven high (output).
Harvard vs Von Neumann
The ATmega328P uses a Harvard-style organization: program memory (Flash) and data memory (SRAM + I/O + EEPROM) are separate address spaces. Instructions are fetched from Flash; LDI, ADD, STS, etc. operate on the data side. The simulator shows Flash as a numbered listing and data SRAM starting at 0x0100 (2 KB), matching the usual AVR data-memory map sketch (registers R0–R31 are modeled separately for clarity).
Instruction cycle (conceptual)
Each Step Fwd performs FETCH → DECODE → EXECUTE: the current Flash line is highlighted, then registers / I/O / flags update. Run repeats steps at a selectable rate (Hz). Step Bwd restores the previous snapshot (limited history) for experimentation.
Memory map (simplified visualization)
Region | Contents |
0x0000–0x001F | 32 general-purpose registers (R0–R31), shown in the register grid |
I/O space | PORTB at 0x05, DDRB at 0x04. OUT 0x05, R16 drives PORTB; pins PB0–PB5 (Arduino D8–D13) light when set to output and the bit is 1 |
0x0100–0x08FF | Internal SRAM (2 KB) — STS / LDS use addresses in this range |
EEPROM | Separate 256-byte array; tutorial opcodes EEWR / EERD are for visualization only |
ALU and SREG
ADD, SUB, and CPI update flags I T H S V N Z C (simplified 8-bit semantics). Z (zero), N (negative / MSB), C (carry / borrow), V (signed overflow), H (half-carry), and S = N ⊕ V are shown as lit tiles when set. BREQ k / BRNE k add 1 + k to the program index when the condition holds (teaching model for relative skip).
Simulation
The interactive simulator is below. Use the controls to explore the concepts described above.
Usage
- Load & Reset — Parses the assembly text area into Flash (non-empty lines), resets registers, SRAM, I/O, PC, SP, and SREG, and rebuilds the Flash listing tab.
- Step Fwd / Step Bwd — Execute one instruction forward or undo one step (stack of snapshots). Stepping stops an active Run.
- Run / Stop — Continuous stepping at Simulation speed (Hz); stops at program end or on error.
- Chip view — Red glow on DIP pins corresponding to PB0–PB5 when DDRB has that bit as output and PORTB is high (default DDRB = outputs on those bits for LED-style demo).
- Memory tabs — SRAM shows the first 256 bytes from 0x0100 (green tint = recently written). EEPROM shows 256 bytes (purple tint when written). Flash listing shows source lines; the current PC line is highlighted.
- Comments — Lines starting with
; are removed before parsing; inline ; / // strip the rest of the line.
Opcodes (subset)
NOP · LDI R16–R31, K · MOV Rd, Rr · ADD Rd, Rr · SUB Rd, Rr · CPI R16–R31, K · OUT A, Rr · IN Rd, A · SBI A, b · CBI A, b · STS addr, Rr / LDS Rd, addr (addr in 0x0100–0x08FF) · PUSH Rr / POP Rd · BREQ k / BRNE k · EEWR addr, Rr / EERD Rd, addr. Immediate and addresses: decimal or 0x hex.
Limitations
This is for visualization and learning, not for compiling real Arduino sketches. Timing, peripherals (ADC, UART, timers), interrupt vectors, and full AVR encoding are not modeled.