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++ > Inline Assembly Syntax

#16062 - DarkPhantom - Sat Feb 07, 2004 4:37 pm

I'm having trouble with getting inline assembly to work with GCC. I'm using VHAM and I think the problem is that VHAM doesn't properly configure the compiler to accomidate it. The compiler doesn't reconginize the "asm" or the "__asm" keywords. It simply rejects that token. Everything works fine if I write an assembly function in its own source file and then assemble it to link with the c code.

In addition, does anybody know how to access link script values like "__sp_usr" without using assembly? I can use an assembly function to return these values i.e.

ld r0,=__sp_usr
bx lr

but I can't figure out the C syntax for the same thing. I tired using

extern unsigned long __sp_usr;

but that only causes the compiler to generate a global varialble.

#16071 - Miked0801 - Sat Feb 07, 2004 5:22 pm

Put a const in front of it and the linker will put it in ROM for you - it's a start :)

#16075 - Paul Shirley - Sat Feb 07, 2004 6:17 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:14 pm; edited 2 times in total

#16076 - Paul Shirley - Sat Feb 07, 2004 6:28 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:14 pm; edited 1 time in total

#16089 - poslundc - Sat Feb 07, 2004 9:36 pm

Be sure to check out the GCC Inline Assembly Rules of Engagement. They may help solve some of the problems you are having.

As for accessing the linkscript variable from C, this is a longshot, but have you tried declaring it as a pointer? Sometimes C is sensitive to that kind of thing, even though it shouldn't be.

Dan.