This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Inline asm
- To: gcc-help at gcc dot gnu dot org
- Subject: Inline asm
- From: Jason Moxham <J dot L dot Moxham at maths dot soton dot ac dot uk>
- Date: Sat, 7 Jul 2001 19:13:10 +0100 (BST)
The following inline asm code compiles to what is expected
under gcc-2.95.3 -fomit-frame-pointer under linux 2.2.19 on intel 386
int main(void)
{unsigned long int a[3]={5,3,8},d=10,*p=a;
asm volatile("\n\
movl (%1),%%eax\n\
shldl %%cl,%%eax,4+(%1)\n\
shll %%cl,(%1)\n\
" : : "c" (d) , "r" (p) : "ax" , "cc" , "memory");
return 0;}
asm below (junk removed)
main:
subl $40,%esp
pushl %ebp
movl $5,20(%esp)
movl $3,24(%esp)
movl $8,28(%esp)
movl $10,16(%esp)
leal 20(%esp),%eax
movl %eax,12(%esp)
movl 16(%esp),%ecx
movl 12(%esp),%edx
#APP
movl (%edx),%eax
shldl %cl,%eax,4+(%edx)
shll %cl,(%edx)
#NO_APP
Here we can see that the array a is
a[0] is stored at 20(%esp)
a[1] is stored at 24(%esp)
a[2] is stroed at 28(%esp)
we therefore should be able to get rid of the register %edx
so trying below
int main(void)
{unsigned long int a[3]={5,3,8},d=10;
asm volatile("\n\
movl %1,%%eax\n\
shldl %%cl,%%eax,4+%1\n\
shll %%cl,%1\n\
" : : "c" (d) , "m" (a) : "ax" , "cc" , "memory");
return 0;}
main:
subl $40,%esp
pushl %ebp
movl $5,20(%esp)
movl $3,24(%esp)
movl $8,28(%esp)
movl $10,16(%esp)
movl 16(%esp),%ecx
leal 20(%esp),%edx
movl %edx,12(%esp)
#APP
movl 12(%esp),%eax
shldl %cl,%eax,4+12(%esp) //wrong memory location here
shll %cl,12(%esp) // and here
#NO_APP
which is clearly wrong
what we want is to have something like
main:
subl $40,%esp
pushl %ebp
movl $5,20(%esp)
movl $3,24(%esp)
movl $8,28(%esp)
movl $10,16(%esp)
movl 16(%esp),%ecx
#APP
movl 20(%esp),%eax
shldl %cl,%eax,4+20(%esp)
shll %cl,20(%esp)
#NO_APP
How do you specify this to the compiler?
And What happens if this was a function and was inlined?
Thanks
Jason Moxham
j.l.moxham@maths.soton.ac.uk