Addressing Modes
The 6502 uses a 16-bit address. There are
65536 bytes of memory available to the processor.
The memory location represented as $0000 -
$ffff. There are 13 ways to refer to these memory locations.
1.Accumulaor
They are eight bits and not located in
memory proper. They are briefly rest here before being sent to another
destination. When you use these there are no additional data are required.
ASL : shift left one bit
C <-
[76543210] <- 0
LSR : shift one bit right
0 >
[76543210] ->c
ROL : Rotate one bit left
C -< [76543210] <- c
ROR : Rotate one bit Right
C
-> [76543210] ->c
2.Absolute
The value given is the address (16-bits) of
a memory location that contains the 8-bit value to be used as constant.
LDA $06d3
STA $0200
3/4.Absolute, X OR Absolute, Y
The final address is found by taking the
given address as a base and adding the current value of the X or Y resister to
it as an offset.
LDA $F453, X : where x contains 3
So, load the accumulator with the contents
of address $f453 + 3= $f456.
5.Immediate
The value given is a number to be used
immediately by the instruction.
LDA #$99 loads the value $99 into the
accumulator.
6.Implied
Many instructions are only one byte in
length and do not reference memory.
CLC – Clear the carry flag
DEX – Decrement the X resister by one
TYT – Transfer the y resister to the
accumulator
RTS – Return from the Subroutine
It pulls the
top two bytes off the stack and transfers program control to that address+1.
Subroutine invoked via JSR which pushed the address -1.
7.Indirect
Indirect addressing uses an absolute address to look up
another address.
JMP($00f0) : jumps to the location pointed to by
addresses $f0 and $f1. So PC=$cc01
LDA #$01
STA $f0
LDA #$cc
STA $f1
JMP ($00f0) ;dereferences to $cc01
8.X, Indirect
LDA ($05, X)
Take the zero page address, add the value of the X
register to it, then use that to look up a two-byte address.
LDX #$01 ; x = $01
LDA #$05
STA $01
LDA #$07
STA $02
LDY #$0A
STY $0705
LDA($00, X) ; think ($00,X) as ( $00 + x) so this
simplified to ($01)
9.Indirect,Y
LDA ($10), Y
Find the 16-bit address contained in the given location.
Add to that address the contents of the Y
resister. Fetch the value stored at that address. It let’s
you have easy access to many locations very quickly by just changing the Y
resister or the pointer. The pointer for this addressing mode must be stored in
zero page locations.
10.Relative
Relative addressing is used with eight instructions
only: BVS, BVC, BCS, BCC, BEQ, BMI, BNE, BPL. They are all “branching”
instructions. Branch on: overflow flag set (or cleared), carry flag set
(or cleared), equal, minus, not-equal, or plus. Branch if Not-Equal, like the
rest of this group, will jump up to 128 addresses forward or backward from
where it is or 127 addresses backward (if the result of the most recent
activity is "not equal"). Note that these jumps can be a distance of
only 128, or 127 back, and they can go in either direction. You specify where
the jump should go by giving an address within these boundaries.
11.Zero page
Zero page is a single-byte address. It use only two hex
digits, any number between $00 and $ff or a decimal number between 0 and 255.
This type of addressing is only the first page of memory is accessible. This is
faster, as only one byte needs to be looked up, and takes up less space in the
assembled code as well.
12.Zero page X
Add the value of the X register to given address.
LDX #$01
LDA #$aa
STA $a0, X ; store the value of A at memory location $a1
INX ; increment X
STA $a0 , X; store the value of A at memory location $a2
13.Zero page Y
when I study this part, it is not easy to understand. it just definition, so I feel that I need practice with sample code. it will help my understanding.