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 > Strange label problem with DevKitPro

#106658 - HyperHacker - Sun Oct 22, 2006 8:40 am

I'm trying to write some ASM routines for a DS app in DevKitPro, and it's treating labels strangely. For example, if I do this:

Code:
SomeFunction:
@blabla
.label:
@blah

SomeOtherFunction:
@foo
.label:
@bar

When it gets to .label in SomeOtherFunction it says .label is already defined. Most assemblers I've worked with treat labels beginning with a period as local to the function they're in; why is this not the case here?
_________________
I'm a PSP hacker now, but I still <3 DS.

#106666 - tepples - Sun Oct 22, 2006 11:37 am

GAS manual: Symbols wrote:
There are ten local symbol names, which are re-used throughout the program. You may refer to them using the names `0' `1' ... `9'.

GAS was intended to postprocess the output of GCC, not to be a tool for compiling assembly language written from whole cloth. So in GAS, there are only ten local symbols, and you can refer to them by names such as 3f (look for the following local symbol 3) or 3b (look for the preceding local symbol 3).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106683 - HyperHacker - Sun Oct 22, 2006 6:41 pm

Ah, so is there a better way to assemble my code, or should I just be prepending the function names to local label names to ensure uniqueness?
_________________
I'm a PSP hacker now, but I still <3 DS.

#106690 - tepples - Sun Oct 22, 2006 7:03 pm

If prepending function names works, then you could write a preprocessor that turns your preferred dialect of assembly into what GAS wants.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106707 - poslundc - Sun Oct 22, 2006 9:10 pm

Or you could just use meaningful label names.

I know it's harder to give names to simple jumps than it is to name functions in a compiled language, but I've written a lot of assembly and never found a jump so inconsequential I couldn't name it.

If you're writing code that ever needs to be reviewed/understood/modified/upgraded, it's a pretty good idea.

Dan.

#106710 - tepples - Sun Oct 22, 2006 9:21 pm

Except the OP wants to reuse the same meaningful labels (e.g. "copyLoop") within multiple functions and thus wants to have labels that are local to a function. CA65 (a 6502 assembler) supports this, but GAS appears not to without a separate preprocessor.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106720 - HyperHacker - Sun Oct 22, 2006 11:42 pm

That's the idea. I have FastCopy and FastFill, which are similar in nature and thus use similar labels.

What about ldr r0, =1234? It doesn't seem to like this either.
_________________
I'm a PSP hacker now, but I still <3 DS.

#106743 - gladius - Mon Oct 23, 2006 4:19 am

ldr r0, =1234 should be fine, you just need a .pool declaration somewhere close by.

As for reusable labels, any integer can be used, not just 0-9. But there is no way I know to have a "nice" label name, and re-use it in plain gas.

#106746 - HyperHacker - Mon Oct 23, 2006 4:40 am

Aha, I found the problem. GAS's syntax is a bit odd: you use ldr r0,=1234, not ldr r0,=#1234 like you would elsewhere (and as No$GBA's disassembly uses). This assembler sure has some odd syntax. (@ for comments?)
_________________
I'm a PSP hacker now, but I still <3 DS.