6502 Mnemonics
The 6502 microprocessor is a popular 8-bit CPU that was widely used in early home computers and video game consoles. It has a relatively simple instruction set, but it is very powerful for its time. Below is a detailed list of the main instructions for the 6502, with explanations, examples, and usage for each.
Data Processing Instructions:
ADC (Add with Carry)
Description: Adds the operand and the carry flag to the accumulator.
Example:
ADC #$10Adds the immediate value
$10and the carry flag to the accumulator.
SBC (Subtract with Borrow)
Description: Subtracts the operand and the carry flag from the accumulator (this is effectively a signed subtraction).
Example:
SBC #$10Subtracts the immediate value
$10and the carry flag from the accumulator.
AND (Logical AND)
Description: Performs a bitwise AND between the accumulator and the operand.
Example:
AND #$FFPerforms a bitwise AND between the accumulator and the immediate value
$FF.
ORA (Logical OR)
Description: Performs a bitwise OR between the accumulator and the operand.
Example:
ORA #$FFPerforms a bitwise OR between the accumulator and the immediate value
$FF.
EOR (Exclusive OR)
Description: Performs a bitwise XOR between the accumulator and the operand.
Example:
EOR #$FFPerforms a bitwise XOR between the accumulator and the immediate value
$FF.
CMP (Compare)
Description: Compares the accumulator with the operand by subtracting the operand from the accumulator.
Example:
CMP #$10Compares the accumulator with the immediate value
$10.
CPX (Compare X Register)
Description: Compares the X register with the operand.
Example:
CPX #$10Compares the X register with the immediate value
$10.
CPY (Compare Y Register)
Description: Compares the Y register with the operand.
Example:
CPY #$10Compares the Y register with the immediate value
$10.
BIT (Bit Test)
Description: Tests specific bits of the accumulator with the operand.
Example:
BIT $2000Tests the bits of the accumulator against the memory at address
$2000.
Load and Store Instructions:
LDA (Load Accumulator)
Description: Loads a value into the accumulator.
Example:
LDA #$10Loads the immediate value
$10into the accumulator.
LDX (Load X Register)
Description: Loads a value into the X register.
Example:
LDX #$10Loads the immediate value
$10into the X register.
LDY (Load Y Register)
Description: Loads a value into the Y register.
Example:
LDY #$10Loads the immediate value
$10into the Y register.
STA (Store Accumulator)
Description: Stores the value in the accumulator into memory.
Example:
STA $2000Stores the value in the accumulator into memory at address
$2000.
STX (Store X Register)
Description: Stores the value in the X register into memory.
Example:
STX $2000Stores the value in the X register into memory at address
$2000.
STY (Store Y Register)
Description: Stores the value in the Y register into memory.
Example:
STY $2000Stores the value in the Y register into memory at address
$2000.
TAX (Transfer Accumulator to X)
Description: Transfers the value in the accumulator to the X register.
Example:
TAXCopies the value from the accumulator into the X register.
TAY (Transfer Accumulator to Y)
Description: Transfers the value in the accumulator to the Y register.
Example:
TAYCopies the value from the accumulator into the Y register.
TXA (Transfer X to Accumulator)
Description: Transfers the value in the X register to the accumulator.
Example:
TXACopies the value from the X register into the accumulator.
TYA (Transfer Y to Accumulator)
Description: Transfers the value in the Y register to the accumulator.
Example:
TYACopies the value from the Y register into the accumulator.
TXS (Transfer X to Stack Pointer)
Description: Transfers the value in the X register to the stack pointer.
Example:
TXSCopies the value from the X register into the stack pointer.
Stack Instructions:
PHA (Push Accumulator)
Description: Pushes the value in the accumulator onto the stack.
Example:
PHAPushes the value in the accumulator onto the stack.
PHP (Push Processor Status)
Description: Pushes the processor status (flags) onto the stack.
Example:
PHPPushes the processor status register onto the stack.
PLA (Pull Accumulator)
Description: Pulls a value from the stack into the accumulator.
Example:
PLAPulls a value from the stack into the accumulator.
PLP (Pull Processor Status)
Description: Pulls a value from the stack into the processor status register.
Example:
PLPPulls a value from the stack into the processor status register.
Branch Instructions:
JMP (Jump)
Description: Unconditionally jumps to the specified memory address.
Example:
JMP $2000Jumps to the address
$2000.
JSR (Jump to Subroutine)
Description: Jumps to a subroutine and pushes the return address onto the stack.
Example:
JSR $2000Jumps to the address
$2000and pushes the return address onto the stack.
RTS (Return from Subroutine)
Description: Returns from a subroutine by pulling the return address from the stack.
Example:
RTSReturns from the subroutine by pulling the return address from the stack.
BEQ (Branch if Equal)
Description: Branches if the zero flag is set.
Example:
BEQ labelBranches to the label if the zero flag is set (i.e., if the last operation resulted in zero).
BNE (Branch if Not Equal)
Description: Branches if the zero flag is clear.
Example:
BNE labelBranches to the label if the zero flag is clear (i.e., if the last operation did not result in zero).
BCC (Branch if Carry Clear)
Description: Branches if the carry flag is clear.
Example:
BCC labelBranches to the label if the carry flag is clear.
BCS (Branch if Carry Set)
Description: Branches if the carry flag is set.
Example:
BCS labelBranches to the label if the carry flag is set.
BMI (Branch if Minus)
Description: Branches if the negative flag is set (i.e., the result of the last operation was negative).
Example:
BMI labelBranches to the label if the negative flag is set.
BPL (Branch if Positive)
Description: Branches if the negative flag is clear (i.e., the result of the last operation was positive).
Example:
BPL labelBranches to the label if the negative flag is clear.
Miscellaneous Instructions:
NOP (No Operation)
Description: Does nothing; typically used for padding or timing purposes.
Example:
NOPDoes nothing and proceeds to the next instruction.
SEC (Set Carry Flag)
Description: Sets the carry flag.
Example:
SECSets the carry flag.
CLC (Clear Carry Flag)
Description: Clears the carry flag.
Example:
CLCClears the carry flag.
SED (Set Decimal Flag)
Description: Sets the decimal mode flag, which affects the BCD (Binary-Coded Decimal) operations.
Example:
SEDSets the decimal mode flag.
CLD (Clear Decimal Flag)
Description: Clears the decimal mode flag.
Example:
CLDClears the decimal mode flag.
SEI (Set Interrupt Disable)
Description: Sets the interrupt disable flag.
Example:
SEISets the interrupt disable flag.
CLI (Clear Interrupt Disable)
Description: Clears the interrupt disable flag.
Example:
CLIClears the interrupt disable flag.
BRK (Break)
Description: Triggers an interrupt, causing the processor to stop executing the current instruction and begin an interrupt service routine.
Example:
BRKTriggers a break interrupt.
This list covers the most important and commonly used instructions in the 6502 processor architecture, including arithmetic, logic, branching, memory operations, stack management, and more. The simplicity of the instruction set made the 6502 a very efficient processor for its time, widely used in gaming consoles, early personal computers, and embedded systems.