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.

Beginners > ARM? THUMB?

#9456 - Domovoi - Tue Aug 05, 2003 11:33 am

I see a lot of references on these forums to ARM and THUMB modes... I searched around in the documentation section, and found some technical info on it, but I can't figure out exactly what they are for, and when you'd use either. Is this strictly for Assembly, or do you have to deal with it when programming in C/C++ as well? Is there any good starters tutorial on it available?

#9466 - tepples - Tue Aug 05, 2003 3:19 pm

Thumb instructions have 16 bits per instruction word and thus will run faster from cart ROM or from EWRAM. Use ARM instructions for those parts of your program that you choose to copy to IWRAM.

The following command lines will let you compile a given source code file in a given architecture:
Code:
gcc -marm -mthumb-interwork (rest of command line)   # compile as ARM
gcc -mthumb -mthumb-interwork (rest of command line) # compile as Thumb

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#9469 - Domovoi - Tue Aug 05, 2003 4:24 pm

Interesting, thanks!

Hmmm... So the more time-critical functions (updating OAM, screen/character base blocks, that sort of thing?) get placed in IWRAM, and less often-used/critical functions in EWRAM?

This brings up another question... How do I know how large my functions are? With such little memory, it'd be useful to keep track of how much memory one is using, exactly...

I suppose you'd only store a handful of functions in IWRAM, so that you have some space reserved for required data and such, right?

#9471 - tepples - Tue Aug 05, 2003 4:53 pm

Domovoi wrote:
So the more time-critical functions (updating OAM, screen/character base blocks, that sort of thing?) get placed in IWRAM, and less often-used/critical functions in EWRAM?

Less often used functions will usually go in ROM, unless you're making a multiboot program. Reasons to make a multiboot program include 1. actual multibooting, or 2. low battery drain.
Quote:
How do I know how large my functions are? With such little memory, it'd be useful to keep track of how much memory one is using, exactly...

nm -n program.elf

Recent Jeff F linker scripts can also overlay the code in IWRAM, so that you can swap out functions that only one part of the program uses. However, I haven't seen a working example of a program that does this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#9476 - DekuTree64 - Tue Aug 05, 2003 7:29 pm

tepples wrote:
Recent Jeff F linker scripts can also overlay the code in IWRAM, so that you can swap out functions that only one part of the program uses. However, I haven't seen a working example of a program that does this.


Quite true. I tried to get it working, but I checked the data map and __iwram_overlay_start was getting set to 0x3001004 or something, and __iwram0_load_start was at 0x3001010, like it was aligning it to the nearest 16-bytes, but not aligning __iwram_overlay_start, so it was getting copied to the wrong place, and missing some instructions at the start of the function, so it locked up.
But one solution I did come up with that works for ASM functions (since you can count up the instructions for the size) is to just declare an array, and copy your code into it, cast it to a function pointer and call it. Works great for interrupt functions that you only need for one effect in a demo, but need to be fast when they're used.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku