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.

Beginners > Inline Assm Problems

#11181 - Twentyfourracing - Sun Sep 28, 2003 2:53 pm

Hello,

I seem to be having a small problem getting this to compile.
I am very new to GBA and GCC. I am trying to us an asm function, 1. for small code space, 2. it's just faster(over all)......?
I know you can just use a C type function, but it compiles a little bigger then the asm version.....

Here is what I am trying to inline.....

Code:
void vblk()
{
                 __asm volatile( "
                                         mov    r0, #0x4000006
                               wait:   ldrh     r1,[r0]
                                         cmp      r1, #160
                                         bne      wait");
}



Thank you.....

Steve

#11184 - tepples - Sun Sep 28, 2003 3:48 pm

First of all, whenever you say you have problems, you should always include the error messages verbatim.

Now, I can see a problem in 'mov'. The ARM architecture doesn't like immediate constants whose bits are spread out across the word. Try building the constant up in two instructions:
Code:
mov r0, #0x4000000
orr r0, r0, #0x00000006

There is a more general solution involving constant pools, but constant pools are tricky to deal with in inline assembly.

EDIT: minor syntax glitch from not having written any serious ARM assembly language from scratch
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Mon Sep 29, 2003 3:49 am; edited 1 time in total

#11185 - Twentyfourracing - Sun Sep 28, 2003 4:33 pm

Yep....... I think I left it out....Hmmm......

Here are the error msg's.....

C:/GBA/test/test.c:80:25: warning: multi-line string literals are deprecated
/cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ccXseucb.s: Assembler messages:
/cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ccXseucb.s:616: Error: Invalid constant


I tried the #0x40000000, orr...... 0x0000006 and it worked..... but I was looking at my .s of the C code and they have an " mov r3, #67108864"....? why is that....?

Here is the C code .s for Ref:
Code:
   .align   2
   .global   WaitVblank
   .type   WaitVblank,function
WaitVblank:
   @ args = 0, pretend = 0, frame = 0
   @ frame_needed = 1, current_function_anonymous_args = 0
   mov   ip, sp
   stmfd   sp!, {fp, ip, lr, pc}
   sub   fp, ip, #4
   mov   r0, r0   @ nop
.L3:
   mov   r3, #67108864
   add   r3, r3, #6
   ldrh   r3, [r3, #0]   @ movhi
   mov   r3, r3, asl #16
   mov   r3, r3, lsr #16
   cmp   r3, #159
   bls   .L3
   ldmea   fp, {fp, sp, pc}
.Lfe2:
   .size   WaitVblank,.Lfe2-WaitVblank


Thank you for getting me going with this....

Steve

#11186 - Twentyfourracing - Sun Sep 28, 2003 4:37 pm

Dang.......


Hmmm..... did you know #67108864(Dec) is 0x4000000(HEX)

oh well..... I should look at it better.......

Thanks again.....