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 and Thumb

#15309 - gbawiz - Tue Jan 20, 2004 7:59 pm

Hello,
What is the meaning of Arm and Thumb, Are they different instruction sets?

#15310 - ampz - Tue Jan 20, 2004 8:01 pm

Yes.

ARM is the 32 bit instruction set.
Thumb is the 16bit instruction set.

#15312 - gbawiz - Tue Jan 20, 2004 8:06 pm

ampz wrote:
Yes.

ARM is the 32 bit instruction set.
Thumb is the 16bit instruction set.


So there is no difference in the assmbly mnemonics?
which is faster, 16bit?

also i cant find any reference to the compiler option '-marm' only '-mthumb'
is '-marm' a new option and what do they do?

Thanks

#15314 - Miked0801 - Tue Jan 20, 2004 8:24 pm

:)

Older versions of GCC had a seperate compiler for Arm and thumb - not a command line switch perhaps that's getting in your way.

GBA Assembly 101:

Thumb almost always runs faster than ARM in ROM because of the 16-bit memory bus. Basically, 32-bit ARM is somewhat hamstrung on this bus.

Arm - if written correctly - will run faster than Thumb in 32-bit IWRAM because of its increased flexibility.

Basically in ARM, you can combine compare/branches and shifts into a 1 cycle op-code and therefore increase your performance. Also, you get double+ the registers in ARM mode which is nice :)

#15319 - poslundc - Tue Jan 20, 2004 8:35 pm

The general strategy is to compile all of your code as Thumb code and leave it in the ROM, for two primary reasons:

- ROM is very, very large and thus is a very good place to keep the majority your code.

- Thumb instructions are 16 bits, and the ROM can only be accessed?16 bits at a time. Therefore if you were to use ARM instructions (which are 32 bits) in ROM it would take two cycles just to load a single instruction.

However, you might want to put small amounts of speed-critical code into IWRAM (which is only 32K large) and compile it as ARM instructions, for the following reasons:

- IWRAM is the fastest area of memory on the GBA - much faster than ROM or EWRAM - so your code loads out of it much quicker.

- IWRAM always accesses 32 bits at a time, so the time to load a 32-bit ARM instruction is the same as the time to load a 16-bit Thumb instruction. Since ARM instructions are much more powerful (as explained by Miked0801), it makes a lot more sense to use them in IWRAM.

The only exception to this is multiboot games, which need to run in EWRAM (usually in Thumb mode as well, since EWRAM reads 16 bits at a time, like ROM). Some people also put their code in EWRAM if it isn't speed-critical because it reduces battery consumption.

Dan.

#15323 - Miked0801 - Tue Jan 20, 2004 8:53 pm

Quote:

Some people also put their code in EWRAM if it isn't speed-critical because it reduces battery consumption.


Where'd you get that bit of trivia from? I hadn't heard that before.

Mike

#15329 - tepples - Tue Jan 20, 2004 9:40 pm

I used to spout that tidbit about power consumption all the time on the gbadev Yahoo! group. I noticed that my multiboot programs were less likely to drive my GBA's battery light red than my ROM-based programs, even with a cart inserted. This indicates that code running from EWRAM makes the CPU draw less current than code running from ROM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#15331 - ampz - Tue Jan 20, 2004 10:00 pm

Yes there is a significant difference in power consumption between EWRAM and cart ROM. The difference is most significant when using a flash cart simply because flash memory consumes alot of current when accessed. The difference is smaller with a ROM cart.