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 > .code 16 or .code 32 ?

#7425 - Lupin - Tue Jun 17, 2003 5:12 pm

I have some questions:

where is the difference between .code 16 or .code 32?

where is the difference between thumb and arm? I compiled an function wich is meant to be thumb code to arm code, without changing anything (expect the function propertys).

What is the advantage/disadvantage of thmb/arm?
And what does .align 1/2/4 mean?

perhaps you could enlighten me ^^

#7450 - tepples - Wed Jun 18, 2003 5:07 am

Lupin wrote:
What is the advantage/disadvantage of thmb/arm?

ARM instructions are 32-bit. Thumb is a 16-bit encoding of a subset of ARM instructions. Sometimes, two or three Thumb instructions are needed to perform the action of a single ARM instruction. Thanks to the magic of interworking (-mthumb-interwork), any ARM or Thumb function can easily call Thumb or ARM functions. However, because the GBA BIOS was compiled without interworking, it expects interrupt service routines (ISRs) to be in ARM instructions.

In general, Thumb code runs faster from 16-bit memory (ROM, VRAM, and EWRAM), but ARM code runs faster from 32-bit memory (IWRAM). Use ARM code in IWRAM for the tightest loops (audio mixer, polygon rasterizer, etc) and for your ISR's entry point, and use Thumb code in EWRAM or ROM for the rest. (Thumb code in EWRAM is ever so slightly slower than Thumb code in ROM, but it uses much less battery power.)

Quote:
And what does .align 1/2/4 mean?

The .align directive pads the binary with zeroes until the current address is a multiple of the given number. Like most other RISC architectures, the ARM architecture can load or store a 4-byte integer value (u32, s32, int, long int) only at an address that's a multiple of 4. Likewise, a 2-byte integer value (u16, s16, short int) needs to be at an address that's a multiple of 2. And because DMA copies require an alignment at least 2, preferably 4, you should align your const data to a 4-byte boundary.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7557 - Lupin - Thu Jun 19, 2003 7:47 pm

thank you for your good explanations!

Do you know an good tutorial to learn ASM? An book would even be better. It's very hard to find good explanations about ASM :(