6502

From Leo's Notes
Revision as of 00:38, 20 June 2020 by Leo (talk | contribs) (Created page with "== Introduction == The MOS Technology 6502 was first released in 1975 and was the dominant CPU in home computers for a decade, appearing in the Atari 2600, Apple II, NES, Comm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 20 June 2020, at 00:38.

Introduction

The MOS Technology 6502 was first released in 1975 and was the dominant CPU in home computers for a decade, appearing in the Atari 2600, Apple II, NES, Commodore PET/VIC20/C64. It is an 8-bit processor with 16 bit address space. It included 3 registers (Accumulator and two general purpose X, Y registers) and a status register.

The instruction sets allowed for loading, storing, and transferring data between the A, X, and Y registers, arithmetic, shifting and rotating, logic AND and OR, comparison, branching, jumping and subroutines, interrupts, and stack operations.

Memory to the 6502 spans its entire 16-bit address space and allows for up to 64 KB of memory to be addressed. Though, this space may also be used for ROM, screen memory, or hardware peripherals. The 6502 organizes memory in the following mapping.

Address Purpose
0000 - 00FF Zero page, for variables
0100 - 01FF Stack

Instruction Set

Description Instructions Examples and notes
Load from memory LDA, LDX, LDY LDA #$22 to load 0x22 to accumulator

LDA $D010 to load value at memory location 0xD010

LDA $0400,X to load the value at 0x0400+Register X useful for index addressing

Store to memory STA, STX, STY
Transfer from Accumulator TAX, TAY
Transfer to Accumulator TXA, TYA Note: No way to directly transfer between registers X and Y
Arithmetic on accumulator ADC add

SBC - subtract

ADC #$02 add 2 to accumulator

ADC $4050 add value at 0x4050 to accumulator

Increment and Decrement INC, INX, INY

DEC, DEX, DEY

Note: May set carry, overflow, or zero flags.
Rotate ROL, ROR Rotate left or right
Shifting ASL, ASR

LSL, LSR

Arithmetic shift will set carry bit, Logical uses carry bit (?)

ASL 1111000 (C=0) results 1110000 (C=1)

LSR 11110000 (C=1) results 11111000 (C=0)

Set Flags SEC, SED, SEI Sets carry, decimal, interrupt
Clear Flags CLC, CLV, CLI, CLD Clear carry, overflow, interrupt, decimal
Jumping JMP
Branching BCC - carry clear

BCS - carry set

BNE - zero clear

BEQ - zero set

BPL - negative clear

BMI - negative set

BVC - overflow clear

BVS - overflow set

Flags

  • Carry set if add/inc >255 or sub/dec <0.
  • Overflow if numbers >255
  • Zero: operation results in 0
  • Negative: bit 7 is set
  • Break
  • Interrupt
  • Decimal