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 > putting code at specific places in memory (with gnu as)

#21033 - BeeWarloc - Sat May 22, 2004 12:05 am

The subject says it all.. How do you do this?
I know how to put code in different sections, but not at absolute positions, like, say, I wanted to put a specific piece of code at 0x03001000...

Thanks for all replies..

#21067 - phonymike - Sat May 22, 2004 9:14 pm

I don't know myself, but I'd like to point out that you'd need to have the code assembled for that location, but also place the code at that point in RAM. So if you did get the code to start at 0x3001000, you'd also need some asm in crt0.s to copy however much code to IWRAM.

#21096 - Lupin - Sun May 23, 2004 8:54 pm

Like phonymike said you have to copy the code by yourself (most likely at startup of your binary). The only problem is that you have to know where the code starts and ends... There must be a way to define sections in gas and to use the section labels to find out the start/end of the sections in the binary, but i really have no idea how to do that because i find GAS very complicated for real ASM programming.
_________________
Team Pokeme
My blog and PM ASM tutorials

#21111 - BeeWarloc - Mon May 24, 2004 1:00 am

I actually figured it out myself... Just had to use the .org directive, and it worked with the standard crt0.s coming with HAM (which I think is almost the same as Jeff's).


Code:



.SECTION .iwram
.CODE 32

@ putting some code in default location (0x3000500 in HAM)
@ (I think this is 0x3000000 in DevKitAdv)

.. some code here ..

@putting some code at 0x3001000 (0x3000500 + 0xb00)
.org 0xb00

.. some more code here..



Be aware that this will only work if using only one object file for this section, or else it will probably be relocated when linking.