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 > Inline Assembly abuse with GNU CC

#7203 - Cyberman - Thu Jun 12, 2003 4:40 am

I've been wanting to abuse inline assembly with GCC for the ARM thumb processor.. I have the ARM manual (pretty straight forward) however the assembly use with the C is not only useful it kind of is mandatory for some things.

I have a function implemented in ARM assembly I would like to translate into inline assembly.. I've looked at the GNU examples and well they kind of are a bit confusing to be honest.

Are there any good examples of multiline (as in thirty or so) inline assembly functions with parameters and local variables in a function used.

Cyb - Thank you in advance.

#7236 - DekuTree64 - Thu Jun 12, 2003 7:17 pm

Check my first reply to the post just below this one (http://forum.gbadev.org/viewtopic.php?t=1430) for how to load and store things to/from local vars. Beware when using inline ASM though, it uses registers to store the input/output args, and doesn't tell you which ones, so if you start changing regs, and then try to access your variables with %0, %1, etc. it could turn out that you've changed one, and it doesn't work anymore. The best way I found to do it was to load each variable one at a time into r0 and store it on the stack (with str r0, [sp, #-4]!) at the start, and then access them from the stack throughout the rest of your block. Be sure to set the stack back to its original location at the end though (add 4*number of things you pushed onto it to sp (or you could probably just specify r13 (different name for sp) in your corrupted regs list, but I always did it myself))