💾 Archived View for vigrey.com › wiki › 6502.gmi captured on 2024-03-21 at 15:03:16. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2024-06-19)

-=-=-=-=-=-=-

6502

The 6502 is an 8-bit microprocessor for MOS Technology in 1975. The instruction set of the 6502 microprocessor is considered by many to be very simple compared to other microprocessors, requiring only 151 opcodes to handle 53 different instructions of different modes.

Many computers and video game consoles of the 1980s used a 6502 microprocessor or a close variation of the 6502 microproccesor, including the Apple II, Atari 2600, Commodore 64, BBC Micro, and the Nintendo Entertainment system.

6502 Pinout

              +---v---+
 (GND) VSS -- |1    40| <- /RST
       RDY -> |2    39| -> CLC2 (OUT)
(OUT) CLC1 <- |3    38| -- SO (Set Overflow)
      /IRQ -> |4    37| -- CLC0 (IN)
      N.C. -- |5    36| -> R/W (Read /Write)
      /NMI -> |6    35| -- N.C.
      SYNC <- |7    34| -- N.C.
 (+5V) VCC -- |8    33| <> D0
        A0 <- |9    32| <> D1
        A1 <- |10   31| <> D2
        A2 <- |11   30| <> D3
        A3 <- |12   29| <> D4
        A4 <- |13   28| <> D5
        A5 <- |14   27| <> D6
        A6 <- |15   26| <> D7
        A7 <- |16   25| -> A15
        A8 <- |17   24| -> A14
        A9 <- |18   23| -> A13
       A10 <- |19   22| -> A12
       A11 <- |20   21| -- VSS (GND)
              +-------+

6502 Instructions

6502 Processor Status Flags

6502 Opcode Modes

ADC - Add with Carry

Adds target memory value and Carry Flag (C) (1 if Carry flag is set [1] or 0 if Carry Flag is clear [0]) to A and stores the result into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

AND - Logical AND

Logical AND operation "A AND target memory" is performed and the result is stored into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

ASL - Arithmetic Shift Left

Shifts all bits of target to the left by 1. 0 is shifted into bit 0 of the target and bit 7 of the target is shifted into Carry Flag (C).

Processor Status After Use:

Mode: Accumulator

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

BCC - Branch if Carry Clear

If Carry Flag (C) is clear (0), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BCS - Branch if Carry Set

If Carry Flag (C) is set (1), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BEQ - Branch if Equal

If Zero Flag (Z) is set (1), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BIT - Bit Test

Logical AND operation "A AND target memory" is performed

Processor Status After Use:

Mode: Zero Page

Mode: Absolute

BMI - Branch if Minus

If Negative Flag (N) is set (1), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BNE - Branch if Not Equal

If Zero Flag (Z) is clear (0), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BPL - Branch if Positive

If Negative Flag (N) is clear (0), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BRK - Force Interrupt

The Program Counter is pushed onto the stack and then Processor Status is pushed onto the stack. Stack Pointer is incremented by 3. Value at IRQ Interrupt Vector ($FFFE-$FFFF) is loaded into Program Counter and Break Command (B) is set (set to 1).

Processor Status After Use:

Mode: Implied

BVC - Branch if Overflow Clear

If Overflow Flag (V) is clear (0), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

BVS - Branch if Overflow Set

If Overflow Flag (V) is set (0), add the argument value to Program Counter

Processor Status After Use:

Mode: Relative

CLC - Clear Carry Flag (C)

Clears Carry Flag (C) (sets to 0)

Processor Status After Use:

Mode: Implied

CLD - Clear Decimal Mode Flag (D)

Clears Decimal Mode Flag (D) (sets to 0). Decimal Mode Flag (D) value is uncertain at power-on.

Processor Status After Use:

Mode: Implied

CLI - Clear Interrupt Disable

Clears Interrupt Disable (I) (sets to 0)

Processor Status After Use:

Mode: Implied

CLV - Clear Overflow Flag (V)

Clears Overflow Flag (V) (sets to 0)

Processor Status After Use:

Mode: Implied

CMP - Compare

Compares A to target memory value

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

CPX - Compare

Compares X to target memory value

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Absolute

CPY - Compare

Compares Y to target memory value

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Absolute

DEC - Decrement Memory

Subtracts 1 from target memory value and stores the result into target memory

Processor Status After Use:

Mode: Zero Page

Mode: Zero Page, X

Mode: Absolute

Mode: Absolute,X

DEX - Decrement X Register

Subtracts 1 from X and stores the result into X

Processor Status After Use:

Mode: Implied

DEY - Decrement Y Register

Subtracts 1 from Y and stores the result into X

Processor Status After Use:

Mode: Implied

EOR - Exclusive OR

Logical XOR operation "A XOR target memory" is performed and the result is stored into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

INC - Increment Memory

Adds 1 to target memory value and stores the result into target memory

Processor Status After Use:

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

INX - Increment X Register

Adds 1 to X and stores the result into X

Processor Status After Use:

Mode: Implied

INY - Increment Y Register

Adds 1 to Y and stores the result into Y

Processor Status After Use:

Mode: Implied

JMP - Jump

Sets Program Counter to address specified by argument. Original 6502 processors mishandle (Indirect) JMP instructions if the low byte of the argument is $FF and will not correctly increment the high byte of the argument by 1. For example, JMP ($10FF) sets the low byte of Program Counter to the value at memory address $10FF, but sets the high byte of Program Counter to the value at memory address $1000 instead of $1100.

Processor Status After Use:

Mode: Absolute

Mode: (Indirect)

JSR - Jump to Subroutine

Pushes the Program Counter minus 1 onto the stack. Program Counter is then set to the argument value. Stack Pointer is incremented by 2.

Processor Status After Use:

Mode: Absolute

LDA - Load Accumulator

Loads value of target memory into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

LDX - Load X Register

Loads value of target memory into X

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,Y

Mode: Absolute

Mode: Absolute,Y

LDY - Load Y Register

Loads value of target memory into Y

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

LSR - Logical Shift Right

Shifts all bits of target to the right by 1. 0 is shifted into bit 7 of the target and bit 0 of the target is shifted into Carry Flag (C).

Processor Status After Use:

Mode: Accumulator

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

NOP - No Operation

No changes happen to the processor besides the normal incrementing of Program Counter to the next instruction.

Processor Status After Use:

Mode: Implied

ORA - Logical Inclusive OR

Logical OR operation "A OR target memory" is performed and the result is stored into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

PHA - Push Accumulator

Pushes copy of the A onto the stack. Stack Pointer is incremented by 1.

Processor Status After Use:

Mode: Implied

PHP - Push Processor Status

Pushes copy of Processor Status onto stack. Stack Pointer is incremented by 1.

Processor Status After Use:

Mode: Implied

PLA - Pull Accumulator

Pops 1 byte from the stack and stores it into A. Stack pointer is decremented by 1.

Processor Status After Use:

Mode: Implied

PLP - Pull Processor Status

Pops 1 byte from the stack and Processor Status is set to that 1 byte. Stack pointer is decremented by 1.

Processor Status After Use:

Mode: Implied

ROL - Rotate Left

Shifts all bits of target to the left by 1. Carry Flag (C) value is shifted into bit 0 of the target and bit 7 of the target is shifted into Carry Flag (C).

Processor Status After Use:

Mode: Accumulator

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

ROR - Rotate Right

Shifts all bits of target to the right by 1. Carry Flag (C) value is shifted into bit 7 of the target and bit 0 of the target is shifted into Carry Flag (C).

Processor Status After Use:

Mode: Accumulator

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

RTI - Return from Interrupt

Pops 1 byte from the stack and sets Processor Status to that byte, then pops 2 more bytes from the stack and sets Program Counter to those 2 bytes. Stack pointer is decremented by 3.

Processor Status After Use:

Mode: Implied

RTS - Return from Subroutine

Pops 2 bytes from the stack and sets Program Counter to those 2 bytes. Program Counter is then incremented by 1. Stack Pointer is decremented by 2.

Processor Status After Use:

Mode: Implied

SBC - Subtract with Carry

Subtracts target memory value and the NOT of Carry Flag (C) (1 if Carry flag is clear [0] or 0 if Carry Flag is set [1]) from A and stores the result into A

Processor Status After Use:

Mode: Immediate

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

SEC - Set Carry Flag (C)

Sets Carry Flag (C) (sets to 1)

Processor Status After Use:

Mode: Implied

SED - Set Decimal Mode Flag (D)

Sets Decimal Mode Flag (D) (sets to 1). Decimal Mode Flag (D) value is uncertain at power-on.

Processor Status After Use:

Mode: Implied

SEI - Set Interrupt Disable

Sets Interrupt Disable (I) (sets to 1)

Processor Status After Use:

Mode: Implied

STA - Store Accumulator

Stores value of A into target memory

Processor Status After Use:

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

Mode: Absolute,X

Mode: Absolute,Y

Mode: (Indirect,X)

Mode: (Indirect),Y

STX - Store X Register

Stores value of X into target memory

Processor Status After Use:

Mode: Zero Page

Mode: Zero Page,Y

Mode: Absolute

STY - Store Y Register

Stores content of Y into target memory

Processor Status After Use:

Mode: Zero Page

Mode: Zero Page,X

Mode: Absolute

TAX - Transfer Accumulator to X

Copies value of A and stores it into X

Processor Status After Use:

Mode: Implied

TAY - Transfer Accumulator to Y

Copies value of A and stores it into Y

Processor Status After Use:

Mode: Implied

TSX - Transfer Stack Pointer to X

Copies value of Stack Pointer and stores it into X

Processor Status After Use:

Mode: Implied

TXA - Transfer X to Accumulator

Copies value of X and stores it into A

Processor Status After Use:

Mode: Implied

TXS - Transfer X to Stack Pointer

Copies value of X and stores it into Stack Pointer

Processor Status After Use:

Mode: Implied

TYA - Transfer Y to Accumulator

Copies value of Y and stores it into A

Processor Status After Use:

Mode: Implied

6502 Opcodes Table

       0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x0_ |BRK|ORA|   |   |   |ORA|ASL|   |PHP|ORA|ASL|   |   |ORA|ASL|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x1_ |BPL|ORA|   |   |   |ORA|ASL|   |CLC|ORA|   |   |   |ORA|ASL|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x2_ |JSR|AND|   |   |BIT|AND|ROL|   |PLP|AND|ROL|   |BIT|AND|ROL|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x3_ |BMI|AND|   |   |   |AND|ROL|   |SEC|AND|   |   |   |AND|ROL|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x4_ |RTI|EOR|   |   |   |EOR|LSR|   |PHA|EOR|LSR|   |JMP|EOR|LSR|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x5_ |BVC|EOR|   |   |   |EOR|LSR|   |CLI|EOR|   |   |   |EOR|LSR|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x6_ |RTS|ADC|   |   |   |ADC|ROR|   |PLA|ADC|ROR|   |JMP|ADC|ROR|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x7_ |BVS|ADC|   |   |   |ADC|ROR|   |SEI|ADC|   |   |   |ADC|ROR|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x8_ |   |STA|   |   |STY|STA|STX|   |DEY|   |TXA|   |STY|STA|STX|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0x9_ |BCC|STA|   |   |STY|STA|STX|   |TYA|STA|TXS|   |   |STA|   |   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xA_ |LDY|LDA|LDX|   |LDY|LDA|LDX|   |TAY|LDA|TAX|   |LDY|LDA|LDX|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xB_ |BCS|LDA|   |   |LDY|LDA|LDX|   |CLV|LDA|TSX|   |LDY|LDA|LDX|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xC_ |CPY|CMP|   |   |CPY|CMP|DEC|   |INY|CMP|DEX|   |CPY|CMP|DEC|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xD_ |BNE|CMP|   |   |   |CMP|DEC|   |CLD|CMP|   |   |   |CMP|DEC|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xE_ |CPX|SBC|   |   |CPX|SBC|INC|   |INX|SBC|NOP|   |CPX|SBC|INC|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0xF_ |BEQ|SBC|   |   |   |SBC|INC|   |SED|SBC|   |   |   |SBC|INC|   |
     +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Incoming Wiki Links

{index}