Page 1 of 1

Confused with indirect addressing

Posted: Fri Jun 04, 2021 6:21 pm
by archie456
Hi,

Newbie question here!

So I want to store a value at memory location $5940.

I have another routine which calculates this memory location and it stores it in zero page as this

Location $70 = $40
Location $71 = $59

So I thought I could indirectly store to this location using:

LDA value to be stored
LDX #0
STA (&70),X

But I can't get this to work, I'd appreciate some advise.

Thanks.

Re: Confused with indirect addressing

Posted: Fri Jun 04, 2021 6:51 pm
by GARTHWILSON
Welcome.

There's (ZP,X) addressing, and there's (ZP),Y addressing, but no (ZP),X addressing. The 65c02 also has (ZP) addressing (with no indexing), so you don't need X or Y for this.

Re: Confused with indirect addressing

Posted: Fri Jun 04, 2021 7:35 pm
by archie456
GARTHWILSON wrote:
Welcome.

There's (ZP,X) addressing, and there's (ZP),Y addressing, but no (ZP),X addressing. The 65c02 also has (ZP) addressing (with no indexing), so you don't need X or Y for this.
Thanks for your response, I found this explanation too:

INDIRECT INDEXED ADDRESSING - In indirect indexed addressing (referred to as ( Indirect) , Y), the second byte of the instruction points to a memory location in page zero.
The contents of this memory location is added to the contents of the Y index register, the result being the low order eight bits of the effective address.


So this should work:

Location $70 = $40
Location $71 = $59

LDA value to be stored
LDY #0
STA (&70),Y

Which should store data in $5940 (made up from $59$40 with zero offset)

Is that correct?

Re: Confused with indirect addressing

Posted: Fri Jun 04, 2021 8:30 pm
by BigDumbDinosaur
archie456 wrote:
Hi,

Newbie question here!

So I want to store a value at memory location $5940.

I have another routine which calculates this memory location and it stores it in zero page as this

Location $70 = $40
Location $71 = $59

So I thought I could indirectly store to this location using:

LDA value to be stored
LDX #0
STA (&70),X

But I can't get this to work, I'd appreciate some advise.

Thanks.

As Garth noted, (<zp>),X addressing doesn't exist. In a syntactically-correct assembler, the form of your code would depend upon whether writing for an NMOS 6502 or a 65C02. In the former case, you would write:

Code: Select all

          LDY #0
          STA ($70),Y

With the 65C02, you can shorten the above to:

Code: Select all

          STA ($70)

Note that in 6502 assembly language, a dollar sign ($) is used to indicate hexadecimal. This is a convention that was inherited from Motorola (the designers of the 6502 were ex-Motorola engineers). Use of the ampersand (&) is ambiguous at best—it's often interpreted as a Boolean symbol for logical AND.

Surrounding the page-zero address with parentheses tells the assembler to use indirection.

Re: Confused with indirect addressing

Posted: Fri Jun 04, 2021 9:08 pm
by archie456
Perfect! Thanks for your responses.

(its a 6502 I'm programming for... Also a BBC Micro which uses & for hex...)

Cheers.