6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Nov 11, 2024 4:13 pm

All times are UTC




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: indirect addressing
PostPosted: Thu Aug 20, 2020 4:57 am 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
I'm coming along with my walk into C64 assembly. I've hit another block though.

Take this code...
Code:
position_1 .byte $51, $04 ;Points to an address in screen memory

The target address is $0451. I need to store the contents of the accum into that memory location.
I've tried different examples from online docs but none work.

Code:
lda #$20
sta ??position_1??,y ; should resolve to "sta $0451,y"

Y is the indexer in this case (ie. $0451 + Y).
I can't figure out how to get the correct address that's pointed to by the high/low byte pair.

C64 with 64tass assembler.

Thanks for helping an old guy realize a childhood dream. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 5:21 am 
Offline

Joined: Sat Jun 04, 2016 10:22 pm
Posts: 483
Location: Australia
What you're doing in that first snippet is putting a label at the assembler's current address, then laying down two bytes starting at that position.
The second snippet is correct, if you remove the question marks.
Your assembler should tell you how to assign a value to a label somewhere in its documentation.


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 5:23 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
position_1 and position_1+1 must both be in zero page, then
Code:
    lda  #$20
    sta  (position_1),y
should store a $20 in address $0451+y (assuming 64tass uses classic 65xx assembly notation).

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 5:29 am 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
I can put them in zero page. Can I just pick an arbitrary location or... ?

[Edit] Found something that said I can safely use $02-$7f.


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 6:00 am 
Offline

Joined: Sat Jun 04, 2016 10:22 pm
Posts: 483
Location: Australia
Oh. I had a braino moment... I'll see myself out...


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 6:03 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
DanielS wrote:
Found something that said I can safely use $02-$7f.

Depends on your definition of "safe".

https://sta.c64.org/cbm64mem.html

$02-$06 and $fb-$fe seem quite safe, by my personal definition.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 12:19 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Sorry! Posted to the wrong forum.

Totally unrelated!


Last edited by IamRob on Fri Aug 21, 2020 5:08 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 12:47 pm 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
Using...
Code:
        lda #$51
        sta position_1
        lda #$04
        sta position_1 + 1
       
        lda     square_data,x
        sta     (position_1),y

        position_1 .byte $02 ;Location in zero page


I get the error
square.asm:26:20: error: not a direct page address address '($18be),y'
sta (position_1),y


That being said... the file that has this code assembles fine by itself. I get the error when I assemble the file that includes (.include "foo.asm") this file.

So I don't know if I'm declaring something wrong or if it's a 64tass thing.


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 1:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
You need position_1 to be the value $02 - but that's not what you have. You need a directive more like an EQU to set the value of position_1.

What you have is position_1 as a label, and then you've placed $02 at that location. That's the sort of thing you do when you want a constant, or some constants, embedded in your program.


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:12 pm 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
BigEd wrote:
You need position_1 to be the value $02 - but that's not what you have. You need a directive more like an EQU to set the value of position_1.

What you have is position_1 as a label, and then you've placed $02 at that location. That's the sort of thing you do when you want a constant, or some constants, embedded in your program.



Could I bother you for a small example?


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:28 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
If I read the manual right, you'd use
Code:
        position_1 = $02 ;Location in zero page
and it might need to be up at the left edge. And it should be before the first point you use it, I think.


Last edited by BigEd on Thu Aug 20, 2020 2:33 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:30 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
Or, an example from the manual, ahead of all of your code:
Code:
*       = $02
position_1   .addr ?         ;a zero page pointer

(But that's very 64tass specific.)


Last edited by BigEd on Thu Aug 20, 2020 2:33 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:32 pm 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
BigEd wrote:
If I read the manual right, you'd use
position_1 = $02 ;Location in zero page
and it might need to be up at the left edge. And it should be before the first point you use it, I think.

Looks like that did it. Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:39 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
DanielS wrote:
I'm coming along with my walk into C64 assembly. I've hit another block though.

Take this code...
Code:
position_1 .byte $51, $04 ;Points to an address in screen memory

The target address is $0451. I need to store the contents of the accum into that memory location.
I've tried different examples from online docs but none work.

Code:
lda #$20
sta ??position_1??,y ; should resolve to "sta $0451,y"

Y is the indexer in this case (ie. $0451 + Y).
I can't figure out how to get the correct address that's pointed to by the high/low byte pair.


Is $0451 a constant or will it be different as your program runs?

If constant, you can do
Code:
    sta     $0451

or better,
Code:
Screen = $0451
    sta     Screen


If you will be writing to other locations nearby, you can do
Code:
Screen = $0451
    ldy     #Offset
    sta     Screen,Y


which is saying store A at Screen+Offset provided you stay within the range $0451..$0550.


Top
 Profile  
Reply with quote  
 Post subject: Re: indirect addressing
PostPosted: Thu Aug 20, 2020 2:52 pm 
Offline

Joined: Wed Aug 12, 2020 2:30 am
Posts: 43
BillG wrote:
If you will be writing to other locations nearby, you can do
Code:
Screen = $0451
    ldy     #Offset
    sta     Screen,Y


which is saying store A at Screen+Offset provided you stay within the range $0451..$0550.


BOOM! Why didn't I think of it this way? This is exactly what I needed. The high/low byte pairs was just complicating something that should be simple. Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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: