Day 24 - Compiling With C

Compiling With C?

	Yep, today we will use both ASM and C++ functions in seperate files and compile
them both.

The C++ File

In test.cpp : /* CODE START */ #include "C:\devkitadv\include\gba.h" extern "C" { void SetThePixel(); /* ASM function uses C conventions */ } int main() { REG_DISPCNT = 0x403; /* mode 3 */ SetThePixel(); /* our ASM function */ while((*KEYS)&KEY_START); /* Wait for start key */ REG_DISPCNT = 0; /* no mode (dot will disappear) */ while(1); return 0; } /* CODE END */

The ASM File

In test.S : @-- CODE START --@ .global SetThePixel SetThePixel: ldr r1,=0x6000200 ldr r2,=0x00FF str r2,[r1] @ red dot somewhere on the screen bx lr @return; @-- CODE END --@ Note: Put a new line at the end of both of the files. Note2: Having the char '\' in a comment assembles, but the ROM doesn't run then, wierd...


Assuming both code files are in the same dir and C:\devkitadv\bin\ is in your path. To compile: gcc test.S test.cpp objcopy -O binary a.out test.gba Then run TEST.GBA to make sure it works.

Day In Review

References: GBADev.ORG Forum Post on this topic Link from that post about why the "extern "C"" is needed. Hope you liked it!, - GBAGuy
Intro - Day 25

Patater GBAGuy Mirror