6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 9:25 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jun 04, 2021 6:21 pm 
Offline

Joined: Fri Jun 04, 2021 5:45 pm
Posts: 5
Location: Chelmsford, Essex
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.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 04, 2021 6:51 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
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.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 04, 2021 7:35 pm 
Offline

Joined: Fri Jun 04, 2021 5:45 pm
Posts: 5
Location: Chelmsford, Essex
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 04, 2021 8:30 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
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:
          LDY #0
          STA ($70),Y

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

Code:
          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!


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 04, 2021 9:08 pm 
Offline

Joined: Fri Jun 04, 2021 5:45 pm
Posts: 5
Location: Chelmsford, Essex
Perfect! Thanks for your responses.

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

Cheers.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


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

Search for:
Jump to: