I am trying to use inline assembler __asm in my C program with Intel syntax as opposed to AT&T syntax. I am compiling with gcc -S -masm=intel test.c
but it is giving error. Below is my test.c file.
#include <stdio.h>
//using namespace std;
int AsmCode(int num,int power) {
__asm {
mov eax, num;
mov ecx, power;
shl eax, cl;
};
}
int main()
{
printf("eax value is %d\n",AsmCode(2,3));
//getchar();
return 0;
}
Expected result was eax value is 16, but errors are occurring like unknown type name 'mov',unknown type name 'shl' etc.
Edit: I have updated the code as:
int AsmCode(int num,int power) {
__asm__ (
"movl eax, num;"
"mov ecx, power;"
"shl eax, cl;"
);
}
int main()
{
printf("eax value is %d\n",AsmCode(2,3));
return 0;
}
And compiled this code with gcc -S -masm=intel test.c
. This resulted in NO OUTPUT, whereas it should produce output as eax value is 16
.
When compiled with gcc test.c
it produced the errors:
Error: too many memory references for 'mov'
Error: too many memory references for 'shl'
Please help..