by Dan East » Dec 20, 2001 @ 9:39am
Hey guys. I just figured out a way to do inline assembly with ARM. I've not tested this, because I don't have time to write the tiny extra program that is required. But here's the technique:<br><br>1) Add the /FAs compiler flag to your C/C++ Project Options. That causes the compiler to produce an ASM listing for each source file, PLUS includes the original C/C++ source listing in the asm file as comments.<br><br>2) In your C/C++ source use a predefined dummy function call to indicate where you want to start inlining. The reason this is needed is to indicate exactly where in the output asm the inline asm is to be inserted. _asm() is a good choice.<br><br>3) Immediately after the _asm() call place a comment block which contains your asm. Something like this:<br>[fixed]<br>int i=0;<br>_asm( ) ;<br>/*<br> {<br> mul r8, r3, r6<br> ;This is my asm comment<br> mov r3, r8, asr #5<br> and r7, r3, #0x3E, 22<br> }<br>*/<br>[/fixed]<br>4) Now for the part that makes this work. A simple program is executed as a custom build step. It simply scans the .asm file looking for calls to the _asm() function. When one is found, it modifies the asm as follows:<br><br>a) Comment out the actual call to _asm, including any stack / register stuff done before / after the branch.<br><br>b) Uncomment out the block of asm the user has in their comments. This would be the lines within the /* { } */ block.<br><br>c) Then your custom program calls armasm, and rebuilds the asm file, which now includes your inline asm code.<br><br>The main caveat is that it is critical that the comments that contain the inline asm fall immediately after the jump to the _asm() routine. The custom program might should check for that, and bump the inline asm up if need be. A quick test showed that comments after a function call do appear directly after the branch. However, there may be cases when the compiler sticks other asm before the comments, so that needs to be taken into consideration.<br><br>Dan East<br><br>[color=blue][sup]Last modification: Dan East - 12/20/01 at 06:39:21