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 > Printing Strings

#174594 - nathanpc - Mon Jun 28, 2010 6:50 pm

Hello,
There is any way that I can print a string(and if possible say the position that it should be written) using Assembly?

Best Regards,
Nathan Paulino Campos
_________________
Reading Tonc and trying to remind my very old C knowledge.

Just bought a GameBoy Advance SP one of those cartridges to put the ROMs for onboard debug.

#174595 - Dwedit - Mon Jun 28, 2010 9:13 pm

Choice #1: Do it yourself. You decide whether you want to just use one tile per character, or make a variable-width font text engine to display text. Tutorials from Tonc look nice.

Choice #2: Use libgba's console functions.

When calling C code from ASM:
r0-r3 = first 4 arguments to a function
r4-r11 should be preserved by the function you call. r0-r3 and r12 are scratch space, and may be trashed. When making your own functions in ASM to call from C, preserve r4-r11.
r0 is the return value for stuff up to 32-bits in size.

Then you just use the BL instruction to call it after you've put stuff into the input registers. And of course, you always push the old link register on the stack before you call anything, so that your function can return. Sometimes people even put the link register into another register instead of using the stack, but that's a little messy.

I don't know offhand how to call a vararg function like printf though, sorry.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#174596 - nathanpc - Mon Jun 28, 2010 9:31 pm

I'm going to make my own library, by plotting pixels. ;)
_________________
Reading Tonc and trying to remind my very old C knowledge.

Just bought a GameBoy Advance SP one of those cartridges to put the ROMs for onboard debug.

#174600 - fincs - Tue Jun 29, 2010 1:21 pm

Dwedit wrote:
I don't know offhand how to call a vararg function like printf though, sorry.

When there are more than 4 arguments to a function the remaining parameters are pushed to the stack.

#174606 - headspin - Wed Jun 30, 2010 7:37 am

We have a section on our forums with some code in asm for displaying text on the DS. Shouldn't be too hard to modify for the GBA. There are a couple of GBA examples too.

http://greatflash.co.uk/index.php?board=12.0
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#174610 - nathanpc - Wed Jun 30, 2010 10:34 am

Thanks for the link. ;)
_________________
Reading Tonc and trying to remind my very old C knowledge.

Just bought a GameBoy Advance SP one of those cartridges to put the ROMs for onboard debug.