[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: General 6502 question



In article <33FE411D.3D76@monmouth.com>,
Daniel Webster  <dwebster@monmouth.com> 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*<expr+1>+<expr>

   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