Basics of 6502 Assembly Language

What is the 6502 Processor?

It is a famous microprocessor from the 1970s and 1980s. It was used in early computers and gaming systems like Apple II, NES. The emulator is a modern program that mimics the behavior of this hardware, allowing you to learn about the 6502's functionality without needing physical hardware.

Core Concepts

1. Registers

Registers are small, fast memory units within the processor that perform tasks:

2. Memory

3. Instructions

The 6502 uses a set of instructions (its "language") to perform tasks. Each instruction has an opcode (operation code):

4. Flags

Flags are 1-bit indicators that show the result of an operation:

Examples to Understand the Concepts Better

Example 1

LDA #5      ; Load the value 5 into the accumulator
CLC          ; Clear the carry flag (important for addition)
ADC #10      ; Add 10 to the accumulator
STA $0200    ; Save the result (15) to memory location $0200
      

Example 2

LDA #8       ; Load the value 8 into the accumulator
SEC          ; Set the carry flag (important for subtraction)
SBC #3       ; Subtract 3 from the accumulator
STA $0300    ; Save the result (5) to memory location $0300
      

Example 3

LDA #5       ; Load the value 5 into the accumulator
STA $0400    ; Save the result (5) to memory location $0400
Loop:        ; This is a label pointing to the next instruction
  LDA $0400  ; Load the current value at $0400
  BEQ DONE   ; If the value is 0, jump to the DONE label
  DEC $0400  ; Decrement the value at $0400
  JMP Loop   ; Jump back to the Loop label
DONE:
  BRK        ; Break (end the program)
      

Explanation for Loop: First, we load value 5 and then check if the value is 0 or not. If it was 0, it jumps to the DONE label and the program ends. Otherwise, it keeps decrementing one value at a time until the value gets to 0 and jumps to the DONE label.

You've visited this page 1 times.