Chapter 2

The Compiler

There used to be 3 choices for GameBoy Advance development (do you spell it developement or development?): ARM SDT, DevKitAdvance, and Goldroad Assembler. Recently, more and more people are using devkitARM, a more generic cross-compiler build of GCC. Today's choices are:

	ARM SDT - Advanced RISC Machines SDK, it wasn't free but there was a hack floating around at the beginning.
		Alot of the older demos are written in C using this. I think it was a build of GCC targetting ARM7.

	DevKitAdvance - A free "kit" of GCC targetting ARM, used for a long while, was the best choice from after
		ARM Corp. got mad about the hack of their SDK, up until recently when DevKitAdvance seems to have
		died. devkitARM uses a newer build of GCC.

	Goldroad Assembler - A one-shot assembler (no C compiler, and no linking either, this baby outputs straight
		binaries). Several older demos also came with a source compatable with this. Hasn't been updated 
		in ages, assumed to be discontinued. Assumed since noone's heard from the author in quite some time.

	devkitARM - A free "kit" of GCC targetting several ARM processors, you need to actually specify what system
		you are dev'ing for, since this "kit" supports GP32, GBA, GBA Multiboot, "and more". This is the "kit" 
		you should get for this tutorial (since I assume you are using it). Any GCC build targetting ARM 
		should work, but this one has things set up well and uses a newer version of GCC than the rest.

There are some other choices for GBA dev, however:

	Dragon BASIC - That's right, a BASIC compiler. From what I've heard, it's pretty good.
		It is shareware though, so to get the best version, you need to pay.

	HAM - A library of functions and macros, and a bunch of other neat stuff that is supposed to 
make it easier to program the GBA. I would assume that this thing sits on top of a GCC build. Note 
that it's shareware, the free version has a required intro screen.

	See the Compiler Section at GbaDev.ORG for all the available
choices (although as I write this, devkitARM isn't on there). Some items on there that I haven't 
described here are yet more GCC builds targetting ARM.

In this tutorial, it will be assumed that you are using devkitARM (version 8 is the latest at time of writing). DevKitAdvance might work, but it's not guaranteed. This tutorial's predecessor was written for the Goldroad Assembler, but since that hasn't been updated in 2 years, the move to a GCC build is quite logical in my opinion. This new tutorial also makes a shift toward using ASM to augment a C program, as such, we will actually use the same program to compile .S (assembly) files as one would use to compile a C program, gcc.

Since we are now using GCC, it will add its own startup code, so even though we will be using ASM, the code won't be all us as it would be if we had a straight binary instead of objects.

Now let's test the compiler, download the devkitARM, and unZIP it to a directory (I used C:\devkitARM_r8\, but I'll probably move that later...). Open a DOS Prompt (CMD.exe for you XP folks (like me)). Make sure the "bin" folder is in the path, I'll assume you're used to using the command line so you know how to do this. If not, search Google for a DOS tutorial. (my statement goes set path=C:\devkitarm_r8\bin;%PATH%)

Put this into a test_1.S file:.arm .text .global main main: mov r0, #0x4000000 mov r1, #0x400 add r1, r1, #3 str r1, [r0] mov r0, #0x6000000 mov r1, #0xFF mov r2, #0x9600 loop1: strh r1, [r0], #2 subs r2, r2, #1 bne loop1 infin: b infin Make sure your current directory is where your test_1.S file is and type the following:
arm-elf-gcc -mthumb-interwork -specs=gba.specs f.S and hit enter.
arm-elf-objcopy -O binary a.out a.gba and hit enter (not gonna say that again).

If no errors are generated, a "a.gba" file will be, run it. It should make a fairly red(ish) screen. Don't worry about understanding the code right now, this is just to make sure you can compile some code. In the next chapter we will start learning the ARM instruction set (THUMB will come somewhat later, since it can look the same in many ways, and several instructions look quite similar).

That's all for now, how about Chapter 3? Or the GBA ASM index?

Note that I use the <listing> tag for a bunch of code, and the <code> tag for one-liners. It would seem that <listing> is an obscure tag. Internet Explorer 6 renders the text kinda small, while FireFox does it the way I want. It was a trade off (as it usually is), since I wanted to use <code> with the "white-space: pre;" CSS, but IE doesn't support it.

Patater GBAGuy Mirror
Contact