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.

Coding > ARM7 ASM Programming with GAS

#9760 - Omega81 - Sat Aug 16, 2003 3:47 pm

Hello everyone.

I have a little problem (a few to be exact but that will be for later). the LDR insuct is only support to be used for loading data from memory to a register isn't it? I mean in Gbaguy's tutorial (http://k2pts.home.comcast.net/gbaguy/day23.htm) he use it to load immediate data directory to a register, this should work as there is only 12bit in the instruction encoding for immedate address so a 26bit address should fail (e.g. ldr r2,=0x6000200). Well my problem is it doesn't and I don't understand why, I am guessing the assembler treats the inclusion of the '=' sign as an immediate assignment and works out the shifts itself. please can anyone correct me if I am wrong or verifiy I am right.
thank you

#9764 - DekuTree64 - Sat Aug 16, 2003 6:18 pm

ldr rn, =value tells it to put the value somewhere after the next .pool directive, and load it from there with a pc-relative load. GAS does seem to find a place for the pool on its own even if you don't specify it yourself, except when you put things in different sections (like .iwram) and then it gives you errors unless you put a .pool somewhere after the .section (generally .pools go at the end of a function, so it's as close as it can get without having to branch over it). Also, if you have a really big function, where the .pool is too far away to reach, you'll get an error. If that happens, you can put a .pool in the middle of your code and just branch over it, but generally if a function is that big, you probably need to split it up anyway, so that's generally not needed, except for sometimes in THUMB mode.

You can also do stuff like
Code:

adr r0, funcData
ldmia r0, {r1-r3}
funcData:
.word var1
.word var2
.word var3

if you have a whole lot of things you want to load all in a row. Adr assembles to an add rn, pc, #offsetToLabel, so that lets you load those vars with 2 instructions instead of 3. I think you can do something like ldr rn, [pc, #funcData + 4] to load var2 alone, but I've never tried it so I'm not sure if that's exactly how it's done. That would let you use the ldm thing, and have the option of just loading one of those values without having to either adr first, or have another copy of it in a .pool for the assembler to load for you.

Generally, .pool is quick and easy, labels give you more control.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku