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.
Confused with indirect addressing
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Confused with indirect addressing
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.
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.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Confused with indirect addressing
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.
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.
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?
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Confused with indirect addressing
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.
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),YWith 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.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Confused with indirect addressing
Perfect! Thanks for your responses.
(its a 6502 I'm programming for... Also a BBC Micro which uses & for hex...)
Cheers.
(its a 6502 I'm programming for... Also a BBC Micro which uses & for hex...)
Cheers.