inline assembly
by vmelkon from LinuxQuestions.org on (#5DPSE)
Hello,
I would like to convert a project (C/C++) to Linux.
x86 and I will change to x64.
The project uses inline assembly in certain places.
Are there any examples? It is easier for me to learn via examples.
I know that I have to use __asm__ ("string goes here")
I know that I have to use AT&T syntax.
Example:
It says that my function does not return a value
Code:int GoGoMMX()
{
__asm__
(
"mov $1, %eax;"
"cpuid;"
"test $0x00800000, %edx;"
"mov $0, %eax;"
"jz NotFound;"
"mov $1, %eax;"
"NotFound:"
"ret;"
);
//return returnVal;
}
This one gives
Warning: no instruction mnemonic suffix given and no register operands; using default for `mov'
Code:int GoGoMMX()
{
int returnVal;
returnVal=0;
__asm__
(
"mov $1, %eax;"
"cpuid;"
"test $0x00800000, %edx;"
"mov $0, %eax;"
"jz NotFound;"
"mov $1, returnVal;"
"NotFound:"
);
return returnVal;
}
}~~~~vmelkon


I would like to convert a project (C/C++) to Linux.
x86 and I will change to x64.
The project uses inline assembly in certain places.
Are there any examples? It is easier for me to learn via examples.
I know that I have to use __asm__ ("string goes here")
I know that I have to use AT&T syntax.
Example:
It says that my function does not return a value
Code:int GoGoMMX()
{
__asm__
(
"mov $1, %eax;"
"cpuid;"
"test $0x00800000, %edx;"
"mov $0, %eax;"
"jz NotFound;"
"mov $1, %eax;"
"NotFound:"
"ret;"
);
//return returnVal;
}
This one gives
Warning: no instruction mnemonic suffix given and no register operands; using default for `mov'
Code:int GoGoMMX()
{
int returnVal;
returnVal=0;
__asm__
(
"mov $1, %eax;"
"cpuid;"
"test $0x00800000, %edx;"
"mov $0, %eax;"
"jz NotFound;"
"mov $1, returnVal;"
"NotFound:"
);
return returnVal;
}
}~~~~vmelkon