inline assembly, C++
I have some C++ code and it contains inline assembly.
It uses the __asm keyword that is VC++ specific.
gcc doess't like it. How to compile this thing?
Thanks, you are the best.
I hwas searching for gcc+assembly and gcc+sse and it was giving topics I was not interested in.
I hwas searching for gcc+assembly and gcc+sse and it was giving topics I was not interested in.
The code has been written a long time ago and also there is IA32 code.
gcc seems to have a different format for the inline assmebly
asm ("mov eax, 0;
mov ecx, 1;
call _foo"
: /* no outputs */
: "g" (from), "g" (to)
: "eax", "ecx"
);
while in VC++ it's
__asm
{
mov eax, 0
mov ecx, 1
call _foo
}
There is some other formats in gcc but they all require a lot of change that is best for a automation tool. Anyone have one handy?
gcc seems to have a different format for the inline assmebly
asm ("mov eax, 0;
mov ecx, 1;
call _foo"
: /* no outputs */
: "g" (from), "g" (to)
: "eax", "ecx"
);
while in VC++ it's
__asm
{
mov eax, 0
mov ecx, 1
call _foo
}
There is some other formats in gcc but they all require a lot of change that is best for a automation tool. Anyone have one handy?
I tried to compile this but it keeps given a error message.
It gives the same error message for the mov instruction : "too many memory references"
/////// I typed this to compile
linux:/MyDocuments # gcc -fPIC -fomit-frame-pointer -g -c asm.cpp
/tmp/cckuMs2Z.s: Assembler messages:
/tmp/cckuMs2Z.s:32: Error: too many memory references for `xor'
//////CODE
int main()
{
__asm__ __volatile__
(
//"mov eax,eax"
"xor eax, eax"
: //No output registers
: //No input registers
: "eax", "ecx", "edx" //Clobber list
);
//".byte 0x0f; .byte 0x31" return 1;
}
It gives the same error message for the mov instruction : "too many memory references"
/////// I typed this to compile
linux:/MyDocuments # gcc -fPIC -fomit-frame-pointer -g -c asm.cpp
/tmp/cckuMs2Z.s: Assembler messages:
/tmp/cckuMs2Z.s:32: Error: too many memory references for `xor'
//////CODE
int main()
{
__asm__ __volatile__
(
//"mov eax,eax"
"xor eax, eax"
: //No output registers
: //No input registers
: "eax", "ecx", "edx" //Clobber list
);
//".byte 0x0f; .byte 0x31" return 1;
}
Try looking at this. It's for DJGPP, but the information applies to any GCC.
For your current problem, you need to prefix the register names with '%', or they will instead be considered to be memory accesses.
For your current problem, you need to prefix the register names with '%', or they will instead be considered to be memory accesses.
I think I tried that one. It didn't work.
Also, I consulted that page. It says the % is for the AT&T syntax.
I use Intel.
Also, I consulted that page. It says the % is for the AT&T syntax.
I use Intel.
int main()
{
__asm__ __volatile__
(
//"mov eax,eax"
"xor %%eax, %%eax"
: //No output registers
: //No input registers
: "eax", "ecx", "edx" //Clobber list
);
//".byte 0x0f; .byte 0x31" return 1;
}
should work, note double %
Quote:Original post by V-man
I think I tried that one. It didn't work.
Also, I consulted that page. It says the % is for the AT&T syntax.
I use Intel.
GCC and its assembler use AT&T syntax. In your example, the double percent-sign is required to prefix the registers.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement