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 > Memory Addressing

#109503 - WangJang - Sat Nov 18, 2006 9:16 pm

*EDIT*

Very sorry, i looked again and i totally missed the "adr" instruction :(

Delete this is need be :)

Sorry to bother, but i have a very noob question.

I searched and could not find what i was looking for, this is what i am trying to do.

i have a set address like:

_ButtonStore: .long 0x04000130

So i can load that by doing.
ldr r0, _ButtonStore

now r0 will contain 0x04000130

But how can i make r0 contain only the location of "_ButtonStore" its self
the address that its reading 0x04000130 from ?

Thanks.

#109529 - DekuTree64 - Sun Nov 19, 2006 1:02 am

Just for reference, adr compiles to a pc-relative add, so it only works with data that's near the current code. To reference a global variable from another file or something, use

ldr r0, =_ButtonStore

That stores a pointer to the variable at the nearest .pool directive, and does a pc-relative load to it. You can also load constants that way, rather than building them a byte at a time with immediate values.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#109560 - WangJang - Sun Nov 19, 2006 9:27 am

Many thanks :)

This actually solved my second problem, all is well now.