Results 1 to 4 of 4
I'm new to the world of linux programming, and this is my first time using inline assembler.
I'm having trouble getting a function implemented in assembler to compile. Well, actually, ...
- 12-04-2009 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 2
GCC's inline assembler - possible syntax error
I'm new to the world of linux programming, and this is my first time using inline assembler.
I'm having trouble getting a function implemented in assembler to compile. Well, actually, it was somehow compiling until I changed the makefile to use the same function with a different main program.
This is the asm code:
And the output from the compiler is:Code:asm("test $0xFFFFFFFF,%ecx; jz Copy_B; Copy_Q:; movq (%0),%%mm0; movq (%1),%%mm1; paddusb %%mm0,%%mm1; movq %%mm1,(%0); add $8,%0; add $8,%1; loop Copy_Q;" ; Copy_B: mov %2,%ecx; ; movb (%0),%eax; movb (%1),%ebx; ; add %ebx,%eax; movb %eax,(%0); inc %0; loop Copy_B" : /*no output registers*/ : "r" (data), "r" (old_data), "r" (size - ((char) size / 8) ), "c" ((char) size / 8) : "%mm0", "%mm1" );
What's even weirder, is that even if I change the makefile to use the old main, it won't compile it. But if I use the old makefile (with the old code), it works perfectly.
Originally Posted by GCC
I tried changing the code layout with no luck, thinking it was a syntax problem, to the following:
And the output this time was:Code:asm( 'test $0xFFFFFFFF,%%ecx' 'jz Copy_B' 'Copy_Q:' 'movq (%0),%%mm0' 'movq (%1),%%mm1' 'paddusb %%mm0,%%mm1' 'movq %%mm1,(%0)' 'add $8,%0' 'add $8,%1' 'loop Copy_Q' 'Copy_B:' 'mov %2,%ecx' 'movb (%0),%eax' 'movb (%1),%ebx' 'add %ebx,%eax' 'movb %eax,(%0)' 'inc %0' 'loop Copy_B' : /*no output registers*/ : "r" (data), "r" (old_data), "r" (size - ((char) size / 8) ), "c" ((char) size / 8) :%mmo,%mm1 );
I've tried looking at several sources for the correct syntax, including GCC's manual, inline assembler's man page, and other internet resources, but they all seemed to point that the syntax used is correct. I'm also puzzled as to why it did compile at first (and still does using the old makefile), yet it won't compile using the same file now with a new makefile.
Originally Posted by GCC
Could anyone please help me figure what's wrong? Any help is greatly appreciated.
- 12-04-2009 #2
Here's a good link that should answer some of your questions
GCC-Inline-Assembly-HOWTOMake mine Arch Linux
- 12-04-2009 #3Just Joined!
- Join Date
- Dec 2009
- Posts
- 2
Thanks for the reply. Unfortunately, that's one of the resources I checked, and the one I based the syntax of the first piece of code on.
- 12-04-2009 #4
Here's a small example of how I use inline in GCC(Note I'm no inline expert)
Code:#include <stdio.h> #include <stdlib.h> typedef void (*pfunc)(unsigned long); void myfunc(unsigned long val) { __asm__ ( "movq 32(%%rsp), %%rax\n\t" "movq %%rax, %0\n\t" :"=m"(val) ); fprintf(stdout, "ans->%lu\n",2 * val); } int main(int argc, char**argv) { pfunc tfunc = (pfunc)myfunc; unsigned long x = 1234; __asm__ ( "pushq %1\n\t" "call *%0\n\t" "addq $8, %%rsp\n\t" :"=m"(tfunc), "=m"(x) ); exit(EXIT_SUCCESS); }Last edited by gerard4143; 12-04-2009 at 08:48 PM.
Make mine Arch Linux


Reply With Quote
