PC relative addressing in SNASMSH2

I was trying to get the following code to work with labels, but I was unable to successfully get it to assemble. Using numbers instead does achieve the desired result, but for a larger program that would be unmanageable. Can someone explain the syntax on how to do this properly.

Code:
	org	$6000000

	mov.l	@(12,pc), r0

	mov.l	@(12,pc), r1

	mov.l	r0, @r1

Loop:

	sleep

	bra	Loop

	nop

Stuff:

	dc.l	"MoDM"

Addy:

	dc.l	$20004020
 

ExCyber

Staff member
I don't know about the SN assembler, but GNU as just lets you do:

Code:
mov.l Stuff, r0

mov.l Addy, r1

mov.l r0, @r1

Loop:

sleep

bra Loop

nop

Stuff:

dc.l "MoDM"

Addy:

dc.l $20004020

I suppose you've probably already tried that, though.

edit: on a possibly more helpful note, check out the IP.BIN sources in SGL, I think they use a non-GNU syntax, but I'm not sure if it's for SNASM, Hitachi's assembler, or something else. It might provide a clue though. I'd check it out myself right now but I need to get to bed about a half hour ago...
 

antime

Extra Hard Mid Boss
You can use the "opt pc+" directive to enable GNU assembler PC-relative syntax, like so:

Code:
opt pc+

mov.l @(foo, pc), r0

foo

dc.l $abcdef00

You could also make your constants EQUates and use the "mov.l =Addy, r1" syntax, just remember to declare a LITS section where the assembler will insert the literals.

Note that putting your code at 0x6000000 is a Bad Thing because the master SH2 vector tables are set to that address. The address normally used (0x6004000) leaves space for both master and slave vector tables and stacks. Also, the address you're writing to is also in the BIOS ROM area, so it won't do much.
 
You can use the "opt pc+" directive to enable GNU assembler PC-relative syntax, like so:

Does this only affect the syntax of PC relative addressing, or does it change everything to be like GAS? In general I don't particularly care for the GNU syntax, but if it only affects PC relative addressing, that's not a problem.

You could also make your constants EQUates and use the "mov.l =Addy, r1" syntax, just remember to declare a LITS section where the assembler will insert the literals.

I tried that and I got different errors. I used LITTAB instead of LITS, but they're supposed to be the same right?

Note that putting your code at 0x6000000 is a Bad Thing because the master SH2 vector tables are set to that address. The address normally used (0x6004000) leaves space for both master and slave vector tables and stacks. Also, the address you're writing to is also in the BIOS ROM area, so it won't do much.

This isn't for Saturn, it's for the 32X. For the time being, I've just set VBR to 0 so it points to the vector table in the boot ROM. On the 32X, main RAM ends at 0x6004000 and the stack builds down from here. On the 32X $20004020 is one of the inter-processor communication registers (not an official name). They can be read or written by both SH-2s and the 68K in the Genesis.

EDIT:

I suppose you've probably already tried that, though.

No, I didn't, but now that I have, that works. I had tried mov.l Stuff(pc), r0 and mov.l @(Stuff, PC), r0 but I hadn't thought to try it that way. Thanks.
 

antime

Extra Hard Mid Boss
Originally posted by Mask of Destiny@Sep 28, 2003 @ 02:52 PM

You can use the "opt pc+" directive to enable GNU assembler PC-relative syntax, like so:

Does this only affect the syntax of PC relative addressing, or does it change everything to be like GAS?

According to the built-in help it just affects PC-relative syntax.

You could also make your constants EQUates and use the "mov.l =Addy, r1" syntax, just remember to declare a LITS section where the assembler will insert the literals.

I tried that and I got different errors. I used LITTAB instead of LITS, but they're supposed to be the same right?

I think they're the same, but try both, just in case. In my few snasmsh2 programs I also used "opt risc+", but I can't remember what it changed. It may have had something to do with the literals. You can check my copperbar sample for one example.

This isn't for Saturn, it's for the 32X.

Ah, OK.
 
Originally posted by antime@Sep 28, 2003 @ 12:12 PM

I think they're the same, but try both, just in case. In my few snasmsh2 programs I also used "opt risc+", but I can't remember what it changed. It may have had something to do with the literals. You can check my copperbar sample for one example.

I think that's it. When I tried using that syntax I got some error about "RISC mode."
 
Top