Assembly Language mnemonics
This section describes, in alphabetical order, all the 6502 assembler mnemonics.
The following abbreviations are used:
A | accumulator |
X | index register X |
Y | index register Y |
F | flags register |
PC | program counter |
PCH | program counter (high byte) |
PCL | program counter (low byte) |
SP | stack pointer |
M | memory address |
← | 'becomes' assignment |
→ | 'affects' flags |
() | contents of |
& | hexadecimal |
(A4) | } } etc. specified bit position in register or memory } |
(M7) | |
(X0) | |
N | } } } } status flags } } } |
V | |
B | |
D | |
I | |
Z | |
C |
Because this section has been written for use with the Electron's assembler, the addressing modes quoted are simplified as compared with those that are specified for use with general machine-code programming of the 6502.
ADC. Add with carry
Action
A←(A) + Data + C
Description
Add the contents of memory location or immediate data to the accumulator, plus the carry bit. Result is placed in the accumulator.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/indexed
Flags affected
NVZC
Comments
To add without the carry, bit C must be cleared beforehand by using CLC.
AND. Logical AND
Action
A←(A) AND Data
Description
AND the contents of memory location or immediate data with the accumulator. Result is placed in the accumulator.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/indexed
Flags affected
NZ
Comments
See BASIC AND for truth table.
ASL. Arithmetic Shift Left
Action
C←A or M←0
Description
Shift the contents of the accumulator or memory location left one bit position. Bit 7 falls into the carry (bit C), zero is entered from the right. Result remains in either the accumulator or the memory location.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Accumulator
Flags affected
NZC
Comments
ASL A acts on the accumulator.
BCC. Branch if carry clear
Action
If bit C is zero, execution continues at the specified label or address. If bit C is 1 then execution continues at the next instruction.
Description
Go to specified label or address if C=0.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BCS. Branch if carry set
Action
Go to specified label or address if C=1
Description
If bit C is 1, execution continues at the specified label or address. If bit C is zero then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BEQ. Branch if equal to zero
Action
Go to specified label or address if Z=1.
Description
If bit Z is 1, execution continues at the specified label or address. If bit Z is zero then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BIT. Compare memory bits with accumulator
Action
(A)
(M)
→F
Description
The accumulator is compared with the contents of a memory location. If the two are the same then bit Z is set to 1; if not then bit Z is cleared. Bits 6 and 7 of the data from memory are loaded into bits X and N respectively. The contents of the accumulator remain unchanged.
Addressing modes
Absolute
Zero-page
Flags affected
NVZ
BMI. Branch if minus
Action
Go to specified label or address if N=1
Description
If bit N is 1, execution continues at the specified label or address. If bit N is zero then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BNE. Branch if not equal to zero
Action
Go to specified label or address if Z=0
Description
If bit Z is zero, execution continues at the specified label or address. If bit Z is 1 then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be range.
BPL. Branch if plus
Action
Go to specified label or address if N=0
Description
If bit N is zero, execution continues at the specified label or address. If bit N is 1 then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BRK. Break
Action
STACK ← (PC) +2
STACK ← (F)
PCL ← (&FFFE)
PCH ← (&FFFF)
Description
This is a software interrupt. The contents of the program counter plus 2 are pushed on the stack, followed by the contents of the flags register. The program counter is then loaded with the contents of locations &FFFE (low byte) and &FFFF (high byte). Bit B is set to 1.
Addressing modes
Implied
Flags affected
B
Comments
Used mainly for error trapping and debugging.
BVC. Branch if overflow clear
Action
Go to specified label or address if V=0
Description
If bit V is zero, execution continues at the specified label or address. If bit V is 1 then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
BVS. Branch if overflow set
Action
Go to specified label or address if V=1
Description
If bit V is 1, execution continues at the specified label or address. If bit V is zero then execution continues at the next instruction.
Addressing modes
Relative
Flags affected
None
Comments
Specified label or address must be in range.
CLC. Clear carry
Action
C ← 0
Description
Bit C is cleared.
Addressing modes
Implied.
Flags affected
C
Comments
Often required before ADC.
CLD. Clear decimal flag
Action
D ← 0
Description
Bit D is cleared, which means that the processor is in binary mode.
Addressing modes
Implied
Flags affected
D
Comments
Should be used at the beginning of all routines which do not use binary coded decimal.
CLI. Clear interrupt mask
Action
I ← 0
Description
Bit I is cleared, which enables interrupts.
Addressing modes
Implied
Flags affected
I
Comments
An interrupt is triggered when an external device, such as a printer, requires attention.
CLV. Clear overflow flag
Action
V ← 0
Description
Bit V is cleared.
Addressing modes
Implied.
Flags affected
V
CMP. Compare with accumulator
Action
(A) − Data → F
Description
Contents of memory location or immediate data are subtracted from the accumulator. If the result is zero then bit Z is set; if not zero it is cleared. If the result is negative then bit N is set; if positive it is cleared. Bit C is set if the accumulator contents are greater than or equal to the data. The contents of the accumulator remain unchanged; only the flags register is affected.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZC
CPX. Compare with X register
Action
(X) − Data → F
Description
Contents of memory location or immediate data are subtracted from the X register. If the result is zero then bit Z is set; if zero it is cleared. If the result is negative then bit N is set; if positive it is cleared. Bit C is set if the X register contents are greater than or equal to the data. The contents of the X register remain unchanged; only the flags register is affected.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZC
CPY. Compare with Y register
Action
(Y) − Data → F
Description
Contents of memory location or immediate data are subtracted from the Y register. If the result is zero then bit Z is set; if not zero it is cleared. If the result is negative then bit N is set; if positive it is cleared. Bit C is set if the Y register contents are greater than or equal to the data. The contents of the Y register remain unchanged; only the flags register is affected.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZC
DEC. Decrement memory
Action
(M) ← (M)-1
Description
The contents of the specified memory are decremented by 1.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Flags affected
NZ
DEX. Decrement X register
Action
X ← (X)-1
Description
The contents of the X register are decremented by 1.
Addressing modes
Implied
Flags affected
NZ
Comments
Enables Y to be used as a counter.
EOR. Logical exclusive-OR
Action
(A) ← (A) EOR Data
Description
Exclusive-OR the contents of memory location or immediate data with the accumulator. Result is placed in the accumulator.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZ
Comments
See BASIC EOR for truth table.
INC. Increment memory
Action
M ← (M) + 1
Description
The contents of the specified memory location are incremented by 1.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Flags affected
NZ
INX. Increment X register
Action
X ← (X)+1
Description
The contents of the X register are incremented by 1.
Addressing modes
Implied
Flags affected
NZ
Comments
Enables X to be used as a counter.
INY. Increment Y register
Action
Y ← (Y)+1
Description
The contents of the Y register are incremented by 1.
Addressing modes
Implied
Flags affected
NZ
Comments
Enables Y to be used as a counter.
JMP. Unconditional jump
Action
PC ← address
Description
Execution continues at the specified label or address.
Addressing modes
Absolute
Indirect
Flags affected
None
Comments
There is no restriction on length of jump; label or address may be anywhere in memory. This is the only instruction which may use straight indirect addressing.
JSR. Jump to subroutine
Action
STACK ← (PC)+2
PC ← address
Description
The contents of the program counter plus 2 are pushed on the stack (this is the address of the instruction following JSR). Execution continues at the specified label or address.
Addressing modes
Absolute
Flags affected
None
Comments
The subroutine to which control is transferred must be terminated by an RTS instruction. JSR is used whenever you wish to make an Operating System call from assembler.
LDA. Load accumulator
Action
A ← Data
Description
Load the accumulator with contents of memory location or immediate data.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZ
LDX. Load X register
Action
X ← Data
Description
Load the X register with contents of memory location or immediate data.
Addressing modes
Immediate
Zero-page
Absolute
Indexed (Y only)
Flags affected
NZ
LDY. Load Y register
Action
Y ← Data
Description
Load the Y register with the contents of memory location or immediate data.
Addressing modes
Immediate
Zero-page
Absolute
Indexed (X only)
Flags affected
NZ
LSR. Logical shift right
Action
0 → A or M → C
Description
Shift the contents of the accumulator or memory location right one bit position. Bit 0 falls into the carry (bit C), zero is entered from the left. Result remains in either the accumulator or memory location.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Accumulator
Flags affected
NZC
Comments
LSR A acts on the accumulator.
NOP. No operation
Action
None
Description
Does nothing for two clock cycles.
Comments
Used for timing a program, or to fill in gaps caused by deleted instructions.
ORA. Logical OR
Action
A ← (A) OR Data
Description
OR the contents of memory location or immediate data with the accumulator. Result is placed in the accumulator.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NZ
Comments
See BASIC OR for truth table.
PHA. Push accumulator on to stack
Action
STACK ← (A)
SP ← (SP)-1
Description
The contents of the accumulator are pushed on to the stack. The stack pointer is decremented. The accumulator contents remain unchanged.
Addressing modes
Implied
Flags affected
None
PHP. Push flags register on to stack
Action
STACK ← (F)
SP ← (SP)-1
Description
The contents of the flags register are pushed on to the stack. The stack pointer is decremented. The flags register contents remain unchanged.
Addressing modes
Implied
Flags affected
None
PLA. Pull data from stack into accumulator
Action
A ← (STACK)
SP ← (SP)+1
Description
Pull the top byte of the stack into the accumulator. Increment the stack pointer.
Addressing modes
Implied
Flags affected
NZ
PLP. Pull data from stack into flags register
Action
F ← (STACK)
SP ← (SP)+1
Description
Pull the top byte of the stack into the flags register. Increment the stack pointer.
Addressing modes
Implied.
Flags affected
NVBDIZC
ROL. Rotate left
Action
A or M
C
Description
Rotate the contents of the accumulator or memory location left one position. The carry (bit C) is entered from the right, bit 7 falls into the carry.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Accumulator
Flags affected
NZC
Comments
ROL A acts on the accumulator. This is a 9-bit rotation.
ROR. Rotate right
Action
A or M
C
Description
Rotate the contents of the accumulator or memory location right one bit position. The carry (bit C) is entered from the left, bit 0 falls into the carry.
Addressing modes
Zero-page
Absolute
Indexed (X only)
Accumulator
Flags affected
NZC
Comments
ROR A acts on the accumulator. This is a 9-bit rotation.
RTI. Return from interrupt
Action
F ← (STACK)
SP ← (SP)+1
PCL ← (STACK)
SP ← (SP)+1
PCH ← (STACK)
SP ← (SP)+1
Description
Restore the contents of the accumulator or memory location right one bit position. The carry (bit C) is entered from the left, bit 0 falls into the carry.
Addressing modes
Implied
Flags affected
NVBDIZC
Comments
Used to return to the execution of a program, after an interrupt has been dealt with.
RTS. Return from subroutine
Action
PCL ← (STACK)
SP ← (SP)+1
PCH ← (STACK)
SP ← (SP)+1
PC ← (PC)+1
Description
Restore the contents of the program counter, which were previously stored on the stack, and increment the program counter by 1. Increment the stack pointer.
Addressing modes
Implied
Flags affected
None
Comments
Continues execution from position after sub-routine call. Used by the Electron's assembler to return to BASIC.
SBC. Subtract with carry
Action
A ← (A) − Data − C
(C is NOT C, which is the borrow.)
Description
Subtract the contents of memory location or immediate data from the accumulator, with borrow. Result is placed in the accumulator.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
NVZC
Comments
To subtract without the borrow, bit C must be set beforehand by using SEC.
SEC. Set carry
Action
C ← 1
Description
Bit C is set.
Addressing modes
Implied.
Flags affected
C
Comments
Often required before SBC.
SED. Set decimal flag
Action
D ← 1
Description
Bit D is set, which means that the processor is in decimal mode (BCD).
Addressing modes
Implied
Flags affected
D
SEI. Set interrupt mask
Action
I ← 1
Description
Bit I is set, which disables interrupts.
Addressing modes
Implied
Flags affected
I
STA. Store accumulator in memory
Action
M ← (A)
Description
Store contents of the accumulator at the specified memory location. The accumulator contents remain unchanged.
Addressing modes
Immediate
Zero-page
Absolute
Indexed
Indirect/Indexed
Flags affected
None
STX. Store X register in memory
Action
M ← (X)
Description
Store contents of X register at the specified memory location. The X register contents remain unchanged.
Addressing modes
Zero-page
Absolute
Indexed (zero-page Y only)
Flags affected
None
STY. Store Y register in memory
Action
M ← (Y)
Description
Store contents of Y register at the specified memory location. The Y register contents remain unchanged.
Addressing modes
Zero-page
Absolute
Indexed (zero-page X only)
Flags affected
None
TAX. Transfer accumulator to X
Action
X ← (A)
Description
Copy the contents of accumulator into X register. The accumulator contents remain unchanged.
Addressing modes
Implied
Flags affected
NZ
TSX. Transfer stack pointer to X
Action
X ← (SP)
Description
Copy the contents of the stack pointer into X register. The stack pointer contents remain unchanged.
Addressing modes
Implied
Flags affected
NZ
TXA. Transfer X register to accumulator
Action
A ← (X)
Description
Copy the contents of the X register into the accumulator. The X register contents remain unchanged.
Addressing modes
Implied
Flags affected
NZ
TXS. Transfer X register to stack pointer
Action
S ← (X)
Description
Copy the contents of the X register into the stack pointer. The X register contents remain unchanged.
Addressing modes
Implied
Flags affected
NZ
TYA. Transfer Y register to accumulator
Action
A ← (Y)
Description
Copy the contents of the Y register into the accumulator. The Y register contents remain unchanged.
Addressing modes
Implied
Flags affected
NZ