ASM6F - Confused how to load a 16-bit pointer into RAM

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
Ben Boldt
Posts: 557
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Ben Boldt » Mon May 04, 2020 9:19 pm

I am playing around with ASM6F and ran into a very basic problem. I haven't used a 6502 assembler ever before so I bet this is probably really simple for someone to explain. I have a table defined in ROM, like this:

Code: Select all

table:
    .byte $00,$01,$02
    ;etc.
Let's say this table is at ROM location $1234. (just an example, not that it is a possible ROM location on NES...) I want to take that label "table" and write it to RAM, say zero-page location $40. Manually, I could do this:

LDA #$34
STA $40
LDA #$12
STA $41

How can I do this using the label 'table'?

I tried this (I forget which >, < was which):

LDA #>table
STA $40
LDA #<table
STA $41

And it assembles to use the correct numbers but as absolute addressing instead of immediate.

LDA $0034
LDA $0012

instead of:
LDA #$34
LDA #$12

Could anyone help me do that the right way? Suggestion to a different assembler also welcome, this one does seem pretty nice though.

User avatar
aa-dav
Posts: 89
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by aa-dav » Mon May 04, 2020 9:27 pm

I use this in CA65:

Code: Select all

; store_addr dest, addr - save address into word in memory
; To avoid lengthy fragments of the same code:
;	lda # < addr	; load LSB of addr
;	sta dest	; save to first byte of dest
;	lda # > addr	; load MSB of addr
;	sta dest + 1	; save to second byte of dest
; let's define macro to write it in one line:
;	store_addr dest, addr	; dest = addr
; dest and addr must be addresses (labels)
; Accumulator is destroyed!
.macro store_addr dest, addr
	lda # < (addr)
	sta dest
	lda # > (addr)
	sta dest + 1
.endmacro
So, it's strange to hear you have problems with it...

User avatar
Controllerhead
Posts: 89
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Controllerhead » Mon May 04, 2020 10:08 pm

Compile with -l and check / post your list file results

Code: Select all

0812D  A9 E3    LDA #>paletteGlobal_BG
0812F  85 04    STA v4
08131  A9 F0    LDA #<paletteGlobal_BG
08133  85 05    STA v5
...
paletteGlobal_BG = $E3F0
It works fine for me

User avatar
Ben Boldt
Posts: 557
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Ben Boldt » Mon May 04, 2020 10:12 pm

Well what the HELL, I tried it again and now it works! I guess I must have had a typo or something. I was working on that for quite a while and ended up just replacing it manually loading the address to drive on at that point... If I get it to do it again I will try to figure out why and report back.

Thanks for your help.

User avatar
Controllerhead
Posts: 89
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Controllerhead » Mon May 04, 2020 10:26 pm

Ben Boldt wrote:
Mon May 04, 2020 10:12 pm
Thanks for your help.
Happy to provide a little sanity check =)

You know, i remember reading in a thread somewhere that you could force Absolute mode, why on Gods green earth you would ever do that is beyond me, tight timing tricks i suppose?

If your file has been open the whole time, maybe save a backup, Ctrl+Z and keep compiling until it screws up again, and then you can figure out what caused it. I am curious so i can be careful myself!

User avatar
Ben Boldt
Posts: 557
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Ben Boldt » Mon May 04, 2020 10:32 pm

I think there was a good chance I was forgetting to save the text file before assembling. :oops:

User avatar
Controllerhead
Posts: 89
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Controllerhead » Mon May 04, 2020 10:43 pm

It's always The Red Disk or The Hashtag Money!

(notepad++ not saved icon and immediate addressing)

Fiskbit
Posts: 120
Joined: Sat Nov 18, 2017 9:15 pm

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by Fiskbit » Tue May 05, 2020 2:00 am

Controllerhead wrote:
Mon May 04, 2020 10:26 pm
You know, i remember reading in a thread somewhere that you could force Absolute mode, why on Gods green earth you would ever do that is beyond me, tight timing tricks i suppose?
Yep. This is a really easy way to inject one cycle of delay, which can't be done by adding another instruction because instructions take at least 2 cycles. Crossing a page boundary is another good approach, but is harder to set up.

tepples
Posts: 22014
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: ASM6F - Confused how to load a 16-bit pointer into RAM

Post by tepples » Tue May 05, 2020 6:42 am

Controllerhead wrote:
Mon May 04, 2020 10:26 pm
You know, i remember reading in a thread somewhere that you could force Absolute mode, why on Gods green earth you would ever do that is beyond me, tight timing tricks i suppose?
That and the 65816 (used in the Apple IIGS computer and Super NES console) reinterprets zero page addresses as "direct page" addresses, which are offsets from a 16-bit index register called D. This is even more important on the HuC6280 (used in the TurboGrafx-16), which always puts direct page at $2000 instead of $0000 but otherwise behaves like a 65C02.

Post Reply