It is currently Tue May 21, 2019 8:34 pm

 All times are UTC - 7 hours

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Is this all the Address Math?Posted: Sun Jan 13, 2019 5:16 am

Joined: Tue Dec 04, 2018 2:28 pm
Posts: 44
Not sure what to call this, but learned something new today. That for certain codes/hex or whatever, you can write an address based on math.

Code:
Zero-Page Indexed

This works just like absolute indexed, but the target address is limited to the first 0xFF bytes.

The target address will wrap around and will always be in the zero page. If the instruction is LDA \$C0,X, and X is \$60, then the target address will be \$20. \$C0+\$60 = \$120, but the carry is discarded in the calculation of the target address.

Indexed Indirect

This mode is only used with the X register. Consider a situation where the instruction is LDA (\$20,X), X contains \$04, and memory at \$24 contains 0024: 74 20, First, X is added to \$20 to get \$24. The target address will be fetched from \$24 resulting in a target address of \$2074. Register A will be loaded with the contents of memory at \$2074.

If X + the immediate byte will wrap around to a zero-page address. So you could code that like targetAddress = (X + opcode[1]) & 0xFF .

Indexed Indirect instructions are 2 bytes - the second byte is the zero-page address - \$20 in the example. Obviously the fetched address has to be stored in the zero page.

Indirect Indexed

This mode is only used with the Y register. It differs in the order that Y is applied to the indirectly fetched address. An example instruction that uses indirect index addressing is LDA (\$86),Y . To calculate the target address, the CPU will first fetch the address stored at zero page location \$86. That address will be added to register Y to get the final target address. For LDA (\$86),Y, if the address stored at \$86 is \$4028 (memory is 0086: 28 40, remember little endian) and register Y contains \$10, then the final target address would be \$4038. Register A will be loaded with the contents of memory at \$4038.

Indirect Indexed instructions are 2 bytes - the second byte is the zero-page address - \$20 in the example. (So the fetched address has to be stored in the zero page.)

While indexed indirect addressing will only generate a zero-page address, this mode's target address is not wrapped - it can be anywhere in the 16-bit address space.

Besides Zero and Indirect, are there any others? Does Immediate or Absolute do this to at all?
This might explain why I couldn't solve the ExciteBike Turbo GG connection.. because I was trying to find "BC C0", but could of easily been another address that connects the two.

Top

 Post subject: Re: Is this all the Address Math?Posted: Sun Jan 13, 2019 7:01 am

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21391
Location: NE Indiana, USA (NTSC)
The 6502's six indexed addressing modes are in fact one of its big practical advantages over the 8080.
Code:
lda aaaa,x  ; Absolute indexed with X
lda aaaa,y  ; Absolute indexed with Y
lda dd,x    ; Direct page* indexed with X
ldx dd,y    ; Direct page indexed with Y (LDX and STX only)
lda (dd,x)  ; Indexed indirect (rarely used outside audio drivers)
lda (dd),y  ; Indirect indexed (very common)

The other modes (immediate, absolute, relative) do not involve addition.

* "Direct page" is the more general term. It is also called "zero page" on 6502 and 65C02 because it is always at page \$0000-\$00FF. On other 6502-like processors, such as 65816, HuC6280, and SPC700, it is elsewhere or relocatable.

_________________
Pin Eight | Twitter | GitHub | Patreon

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: Google [Bot] and 10 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki