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.

C/C++ > optimization -O3 and inline asm problems

#12174 - johnny_north - Sun Nov 02, 2003 7:28 am

Hello-

Maybe this question belongs in the asm forum...

I've been using the mbclient code from over at gba devr's. With no optimizations the code compiles fine, but when I compile at -O3, the compiler gives the following errors:

/cygdrive/c/WINDOWS/TEMP/cc0c07vF.s: Assembler messages:
/cygdrive/c/WINDOWS/TEMP/cc0c07vF.s:1141: Error: Symbol MultiBootWaitCyclesLoop already defined.

from the code:

Code:
  /* GCC code16 */
  asm("mov r2, pc");
  asm("lsr r2, #24");

  // EWRAM
  asm("mov r1, #12");
  asm("cmp r2, #0x02");
  asm("beq MultiBootWaitCyclesLoop");

  // ROM 4/2 wait
  asm("mov r1, #14");
  asm("cmp r2, #0x08");
  asm("beq MultiBootWaitCyclesLoop");

  // IWRAM
  asm("mov r1, #4");

  asm("MultiBootWaitCyclesLoop:");
  asm("sub r0, r1");
  asm("bgt MultiBootWaitCyclesLoop");


I'm ignorant when it comes to assembly, but I can see that there's no redefinition - one lable and three branches to that lable. Anyone know what changes I can make to this to get it to assemble properly?

#12175 - johnny_north - Sun Nov 02, 2003 7:37 am

Matter of fact, all inline labes cause an error:

Code:
asm("MultiBootWaitCycles:");

/cygdrive/c/WINDOWS/TEMP/ccBU3dNe.s: Assembler messages:
/cygdrive/c/WINDOWS/TEMP/ccBU3dNe.s:1135: Error: Symbol MultiBootWaitCycles already defined.

Code:
asm("MultiBootWait:");

/cygdrive/c/WINDOWS/TEMP/ccd467kb.s: Assembler messages:
/cygdrive/c/WINDOWS/TEMP/ccd467kb.s:1135: Error: Symbol MultiBootWait already defined.

Code:
asm("MultiBoot:");

/cygdrive/c/WINDOWS/TEMP/cc43AgC4.s: Assembler messages:
/cygdrive/c/WINDOWS/TEMP/cc43AgC4.s:1135: Error: Symbol MultiBoot already defined.

#12180 - DekuTree64 - Sun Nov 02, 2003 5:07 pm

Inline assembly is icky. Try putting it in a pure ASM function in a .s file. Just compile it to a .o with gcc like any other file. It should look something like this:
Code:

.thumb
.align 2
.global MB
MB:
push {r4-r7} @if you need more than r0-r3
@do stuff
pop {r4-r7} @if you pushed them before
bx lr

_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku