I'm trying to execute inline assembly, giving a variable as input
void main(void)
{
char a[20] = "mov edx, 88";
asm("%[a]" : : [a]"r"(a));
}
But :
gcc a.c -masm=intel
Error: no such instruction: `eax'
How can I make this work ?
I'm trying to execute inline assembly, giving a variable as input
void main(void)
{
char a[20] = "mov edx, 88";
asm("%[a]" : : [a]"r"(a));
}
But :
gcc a.c -masm=intel
Error: no such instruction: `eax'
How can I make this work ?
The instructions must be in a form of a string literal(actual written string, the name of a char array is a pointer btw). Other than that you got the general idea:)
#include <stdio.h>
int main(int argc, char ** argv){
char a[20] = "nice try:)";
char * dst;
asm("mov %[dst], %[src]\n\t"
: [dst]"=r" (dst) : [src]"r"(a));
printf("%s\n", dst);
return 0;
}
and a useful link: https://dmalcolm.fedorapeople.org/gcc/2015-08-31/rst-experiment/how-to-use-inline-assembly-language-in-c-code.html