6502 Addressing Modes

From CDOT Wiki
Revision as of 20:57, 14 January 2020 by Chris Tyler (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The 6502 processor has 13 Addressing Modes. Not all addressing modes are valid for every instruction.

Accumulator

The operation works on the accumulator. No additional data is required. Examples:

ASL A
LSR A
ROL A
ROR A

Note that the explicit A is not required by most assemblers, so you could write:

ASL
LSR
ROL
ROR

Absolute

Data is accessed using 16-bit address specified as a constant.

LDA $06d3
STX $0200

Absolute, X

Data is accessed using a 16-bit address specified as a constant, to which the value of the X register is added (with carry).

LDA $8000,x
STA $8000,x

Absolute, Y

Data is accessed using a 16-bit address specified as a constant, to which the value of the X register is added (with carry).

LDA $8000,y
STA $8000,y

Immediate

Data is taken from the byte following the opcode.

LDA #$05
ORA #$80

Implied

The data is implied by the operation. Examples:

CLC
RTS

Indirect

Data is accessed using a pointer. The 16-bit address of the pointer is given in the two bytes following the opcode.

JMP ($9000) ; Jumps to the location pointed to by addresses $9000 (low) and $9001 (high)

X, Indirect

An 8-bit zero-page address and the X register are added, without carry (if the addition overflows, the address wraps around within page 0). The resulting address is used as a pointer to the data being accessed. Note that, effectively, this makes the X register an index into a list of pointers.

LDA ($05,x)

Indirect, Y

An 8-bit address identifies a pointer. The value of the Y register is added to the address contained in the pointer. Effectively, the pointer is the base address and the Y register is an index past that base address.

LDA ($10),y

Relative

An 8-bit signed offset is provided. This value is added to the program counter (PC) to find the effective address.

BNE $0600 ; The value "$0600" is assembled into a signed offset. If the target must be in the range of (-128:127) bytes of the current PC value.

Zero page

An 8-bit address is provided within the zero page.

LDX $13
AND $07

Zero page, X

An 8-bit address is provided, to which the X register is added (without carry - if the addition overflows, the address wraps around within the zero page).

STA $00,x
LDA $00,x

Zero page, Y

An 8-bit address is provided, to which the Y register is added (without carry - if the addition overflows, the address wraps around within the zero page).

STA $00,y
LDA $00,y