Classroom Public page

Lab 3.1: Work Through Easy 6502 (Nick Morgan)

756 words

~120 minutes. Walk through Nick Morgan's free in-browser 6502 tutorial. Write small 6502 programs. End with your own short program that prints text.


Goal: gain working familiarity with 6502 assembly by following a guided in-browser tutorial; write at least one short program from scratch by the end.

Estimated time: 120 minutes

Prerequisites: lab 2.1 and 2.2 complete (you know what bytes in a ROM are; now learn what they MEAN as instructions)

Steps

Step 1: Open Easy 6502 (5 minutes)

Open https://skilldrick.github.io/easy6502/ in your browser. This is Nick Morgan's free tutorial; it includes an in-browser 6502 assembler and simulator.

You will see:

  • A long explanatory page on the left
  • Several embedded code editors throughout the page where you can write and run 6502 code
  • A "simulator" widget that visualizes a 32x32 pixel display (NOT a NES; a simpler hardware mock-up Nick built for teaching)

Step 2: Read sections 1-4 carefully and run the examples (40 minutes)

Read the page from the top. When you reach an embedded code editor with example code:

  1. Read the code
  2. Click "Assemble" to assemble it (or whatever button the editor shows)
  3. Click "Run" to execute it
  4. Observe what changes in the simulator

The sections to work through:

  • Section 1: What is 6502 assembly language? (5 min, orientation)
  • Section 2: First steps (15 min, your first LDA, STA; you set memory bytes and see the pixels turn on)
  • Section 3: Hello, world! (10 min, slightly bigger program; loops with branches)
  • Section 4: Registers and flags (10 min, A, X, Y registers; the status flags Z, N, C, V)

Take notes in your journal as you go:

  • What does LDA #$01 do? (Load Accumulator with the immediate value 0x01)
  • What does STA $0200 do? (Store Accumulator into memory address 0x0200)
  • What does INX do? (Increment X register)
  • What does BNE do? (Branch on Not Equal, branch if the Z flag is not set)

Step 3: Work through sections 5-7 (40 minutes)

  • Section 5: Instructions (15 min, the full instruction set; do not memorize, just skim and note that there are ~56 unique instructions and you have already met most of them)
  • Section 6: Branching (10 min, BEQ, BNE, BCC, BCS, etc.; you write your first loop)
  • Section 7: Addressing modes (15 min, LDA #$01 vs LDA $01 vs LDA $0200,X; the different ways to refer to memory)

Run the examples. Edit them to do something slightly different. See what happens.

Step 4: Write your own short program (25 minutes)

Now write a program from scratch. Suggested options:

  • Fill a 16×16 area of the simulator with a single color
  • Make a 2×2 square move across the screen one pixel at a time
  • Print your initials by setting specific pixels to specific colors
  • Anything else that catches your imagination

Approximate structure for the "fill area" program:

; Fill a 16x16 area starting at $0200 with color 1
  LDA #$01      ; load color 1 into A
  LDX #$00      ; X is our loop counter

loop:
  STA $0200,X   ; store color at $0200 + X
  INX           ; increment X
  CPX #$10      ; have we done 16 stores?
  BNE loop      ; if not, loop again

  ; (Now do the next row, and the next, etc.)

Get a working version. Iterate. Make it do what you want.

Step 5: Journal what you wrote (10 minutes)

Open ~/spk-101/journal/lab-3-1-notes.md. Capture:

  • A copy of the program you wrote
  • What it does
  • What you tried that did NOT work first
  • The moment something "clicked", when did 6502 start to feel less mysterious?

Expected output

  • Worked through Easy 6502 sections 1-7
  • Wrote at least one original 6502 program (~10+ instructions) that does something visible in the simulator
  • Journal entry with the program text and your reflection

Common pitfalls

  • LDA #$01 vs LDA $01: the # matters. LDA #$01 loads the literal value 1; LDA $01 loads the byte stored at memory address 0x01. These are different things
  • Forgetting that branches are signed offsets: branches in 6502 are relative jumps of -128 to +127 bytes. If your branch target is too far, the assembler will warn you. For Easy 6502 programs you will not run into this; just know the limit exists
  • Confusing the simulator with a real NES: Easy 6502's simulator is a simplified teaching environment, not a NES. The memory map and graphics are simpler. Lab 3.2 puts you on a real NES via Mesen
  • Trying to memorize the full instruction set: do not. Use the cheatsheet on https://www.6502.org/. The same handful of instructions (LDA, STA, ADC, SBC, CPX/CPY, BEQ/BNE/BCC/BCS, JMP, JSR, RTS) cover most code

Stretch (optional)

If you finished early:

  • Continue to Easy 6502 sections 8 and 9 (subroutines and a small text adventure)
  • Rewrite your fill-area program to use a nested loop (outer loop over rows, inner loop over columns) to fill the full screen
  • Modify one of the page's examples, change a color, change a loop condition, see what changes

Lab 3.1 v0.1. Foundational, week 3 onward expects basic 6502 literacy.