Everything2
Near Matches
Ignore Exact
Full Text
Everything2

6502 addressing modes

created by yerricde

(idea) by yerricde (8.5 mon) (print)   ?   (I like it!) 1 C! Sat Mar 31 2001 at 21:48:32

The 6502 processor had quite a few addressing modes for its time.
name            abbr    len time formula for N  example
implied         impl    1   2    ---            tay
immediate       imm     2   2    arg            ora #$f0
zero page       dp      2   3    *arg           cmp $56
zero page,x     d,x     2   4    *(arg+x & $ff) adc $56,x
zero page,y     d,y     2   4    *(arg+y & $ff) ldx $56,y
absolute        abs     3   4    *arg           eor $3456
absolute,x      a,x     3   4i   *(arg+x)       and $3456,x
absolute,y      a,y     3   4i   *(arg+y)       sbc $3456,y
indirect,x      (d,x)   2   6    **(arg+x)      lda ($34,x)
indirect,y      (d),y   2   5i   *(*arg+y)      sta ($34),y
relative        rel     2   2tc  *(PC+arg)      beq loop

Zero page refers to the first 256 bytes of memory. But on later 6502 family processors such as WDC's 65C816, the zero page instructions instead access the "direct page" (thus the abbreviation "dp"), whose base address can be moved anywhere in the first 64 KB of RAM, with a one-cycle penalty if the base of the direct page doesn't lie on a 256-byte boundary.

  • t: add a cycle if the branch is taken
  • c: add a cycle for crossing 256-byte boundaries
  • i: add a cycle except on reads not crossing 256-byte boundaries
  • Always add two cycles for atomic read-modify-write instructions (inc, dec, asl, lsr, rol, ror, 65c02 tsb, and 65c02 trb).

Some instructions have their own addressing modes. These are explained in each instruction's writeup.

Addressing modes d,x d,y (d,x) and (d,y) wrap around inside the zero page. For example:

  ldx #$ff
  lda $80,x
This will load from $007f instead of $017f. If you take advantage of this, please COMMENT IT!

The original 6502 has a small bug (or feature) that wraps the vector that jmp (a) pulls inside a 256-byte area. See 6502 indirect JMP bug for more explanation.

PC-relative instructions count from the END of the instruction they're in.

See also: 6502 instructions
Return to NES programming


printable version
chaos

6502 indirect JMP bug 6502 instructions NES programming zero page
LDA Stupidest thing you've coded just to see if you could TAY CPY
2A03 God comments his code, you should too bit ADC
PHP LDX CMP 6502
CLI
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Just another sprinkling of indeterminacy
Her name was Natalie
Stay Gold, Ponyboy
Danzayémon, Chief of the Etas
George Harrison takes a vacation
Nebuchadnezzar
Seagull in the city
Brian Downing
Transformers Tech Specs
Fingers slick with mythos
Escherichia coli
Lightning Crashes
When I left home
Dead Sea Scrolls
New Writeups
The Jacket
Words of Advice(idea)
keepinitreal
Why buy the cow when you can get the milk for free?(idea)
John_Fox
Good Intentions Gone Wrong(person)
Cuckowski
Slavonic Princess(poetry)
Heitah
Posthumous Oscar(thing)
ignis_glaciesque
University of South Florida(place)
ignis_glaciesque
Flogstaskriket(idea)
liveforever
Caesar's last breath(idea)
dagnyswaggart
she wants to believe(personal)
antigravpussy
he doesn't know, but her eyes widen too far(thing)
dagnyswaggart
Wild tides guard her secrets(poetry)
Lord Brawl
Caesar's last breath(poetry)
locke baron
Forgotten things in space(fiction)
sitaraika
Colours(idea)
etouffee
Wild tides guard her secrets(poetry)
Everything 2 is brought to you by the letter C and The Everything Development Company