Path: news1.icaen!news.uiowa.edu!news1.chicago.cic.net!iagnet.net!howland.erols.net!infeed1.internetmci.com!newsfeed.internetmci.com!206.172.150.11!news1.bellglobal.com!bellglobal.com!not-for-mail From: Scott Gregory Newsgroups: comp.emulators.apple2,comp.sys.apple2,comp.sys.apple2.programmer Subject: Re: General 6502 question Date: Mon, 25 Aug 1997 08:30:30 -0400 Organization: Bell Network Solutions Lines: 26 Message-ID: <34017AE6.9649A481@fp.cibc.com> References: <01bcae0b$68b580d0$4752329f@pc_fit3> <33FE0A70.7507@monmouth.com> NNTP-Posting-Host: 207.61.221.18 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.01 [en] (WinNT; U) X-Priority: 3 (Normal) Xref: news1.icaen comp.emulators.apple2:12865 comp.sys.apple2:124403 comp.sys.apple2.programmer:9311 Daniel Webster wrote: > I am trying to disassmble a program, and its been a while since I've > hacked 6502 code. I know that STA ($26),y is indirect addressing, but > > what does LDA ($26,X) do? > > Thanks > Dan These are the two famous indirect modes of the 6502. "Indexed Indirect" and "Indirect Indexed" - the order is very important... STA ($26),Y - Indirect Indexed, use location pointed to by $26,27, add Y STA ($26,X) - Indexed Indirect, use location pointed to by $26+X,$26+X+1 Enjoy (p.s. Just picked up a real Apple //e, dual disk, Z80 card and am in nostalgia heaven.) sdg Path: news1.icaen!news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!vixen.cso.uiuc.edu!ais.net!visi.com!news-out.visi.com!not-for-mail From: nathan@visi.com (Nathan Mates) Newsgroups: comp.sys.apple2,comp.sys.apple2.programmer Subject: Re: General 6502 question Date: 23 Aug 1997 04:59:56 GMT Organization: Vector Internet Services, Inc. Lines: 62 Message-ID: <5tlqoc$q3$1@darla.visi.com> References: <01bcae0b$68b580d0$4752329f@pc_fit3> <33FE0A70.7507@monmouth.com> <5tl1j4$dch$1@darla.visi.com> <33FE411D.3D76@monmouth.com> NNTP-Posting-Host: thumper.visi.com NNTP-Posting-Date: 22 Aug 1997 23:59:56 CDT Xref: news1.icaen comp.sys.apple2:124407 comp.sys.apple2.programmer:9312 In article <33FE411D.3D76@monmouth.com>, Daniel Webster wrote: >>> I know that STA ($26),y is indirect addressing, but what does LDA >>> ($26,X) do? >> Think of it as lda ($26+X). Adds $26 to the X-register, and >> dereferences that zeropage 2-byte pointer. >Thanks Nate, but just so I am clear on this, it takes the contents of >the zero page address, adds the contents of the X register and loads >that number in the accumulator or does it load the contents of the >address at $26+X? As I said, it dereferences [i.e. looks up an address from] the 2-byte pointer. In 65xx asm syntax, (expr) uses the contents of expr and expr+1 as an address to load/save from. 'expr' must be a zero page address, and remember, first byte is the low byte of the address, so the address is 256*+ With (const,X), the sum of the const and X is the address to use. For example, assume the following set of bytes: 26: 04 0F 56 0E 87 0F 0F04: 99 AA BB CC DD EE FF 0E56: 88 870E: 77 Thus, (26) [this form only available on 65C02 and up] retrieves the byte at 0F04, or 99. If X=0, (26,X) is the byte at 0F04 again; x=2 is essentially (28) or the byte at 0E56, i.e. 88, x=3 is essentially (29) or the byte at 870E, i.e. 77. Putting an offest outside the parens, such as 'LDA (26),Y' means to dereference to get the address and then add the Y register to that address before loading. Thus, (26),Y with Y=0 is the byte at 0F04 i.e. 99, (26),Y with Y=1 is the byte at 0F05 i.e. AA and so on > The reason I am unclear on this is I am trying to differentiate it > from LDA $5000,X (a non zero page address) As there are no parentheses, there is no dereferencing going on here. X is added to 5000 to get an address and the byte there is retrieved. For example given memory as follows: 5000: 10 11 12 13 14 15 16 LDA 5000,X with X=0 get the byte at 5000 i.e. 10; LDA 5000,X with X=1 gets the byte at 5001, i.e. 11. As there are no parentheses [and there can't be as 5000 is out of the zero page], there is no address dereferencing going on, just simple addition. Hopefully my examples above have helped a little. On the 65816, there's a 24-bit dereference from the direct page; LDA [26] uses 26-28 as an address and gets the byte from <28>/<27><26>. Nathan Mates -- <*> Nathan Mates http://www.visi.com/~nathan/ <*> # What are the facts? Again and again and again-- what are the _facts_? # Shun wishful thinking, avoid opinion, care not what the neighbors # think-- what are the facts, and to how many decimal places? -R.A. Heinlein