gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > GCC equivalent to SDT's MAP directive?

#91865 - Dwedit - Mon Jul 10, 2006 8:37 am

Does GCC have an equivalent to ARM SDT's MAP directive? PocketNES heavily uses this feature, and it would be hard to do without it.

The MAP directive takes in a register, then defines offsets from that register.
for example:
MAP 0,r11
nes_ram # 0x800
nes_sram # 0x2000
chr_decode # 0x400
...

Here nes_sram becomes [r11+0x800] when used in an instruction like ldr r0,nes_sram
But also you can do ldr r2,nes_sram+4, and it will just work. You can also use the ADR instruction to generate an address (it just turns it into addition).
Any equivalents in GCC?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#92000 - tepples - Tue Jul 11, 2006 12:38 am

You could probably build something similar using C preprocessor macros.
Code:
#define nes_ram(off)    [r11+off]
#define nes_sram(off)   nes_ram(0x800+off)
#define chr_decode(off) nes_sram(0x2000+off)

Then you can specify that you want C preprocessing applied to your .s file by passing the flag -x assembler-with-cpp to GCC when compiling the .s file.

It's also possible to use the file name suffix .S instead of .s to add automatic C preprocessing to the assembler, but I wouldn't recommend it on a case-insensitive file system such as all file systems shipped with Microsoft Windows.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.