Mail Archives: djgpp/1998/05/04/20:11:20
At 09:24 5/4/1998 -0700, Xavi Cardona wrote:
>!
>I'm starting assembler programming. I have read all FAQs,docs & txt
>about this, but I don't know why this program not works:
>
>/* Program asmvar.cc: this program puts 10 in myvar */
>#include <stdio.h>
>main()
>{char myvar =0;
>__asm__ __volatile__ ("movb $10,_myvar"
> :
> :
> :"memory");
>printf("i=%d\n",myvar);
>}
>
>I compile it with:
> gcc -O2 -o asmvar.exe asmvar.cc
>
>But, the result is:
> In function main
> undefined reference to "_myvar"
Because in C++ variable names are mangled, and local variables lose their
names before assembly time anyway. This is why GCC has its extended
assembly. Try:
char myvar = 0;
asm("movb $10, %0"
: "=g" (myvar)
: ); /* no inputs, nothing unusual clobbered */
Nate Eldredge
nate AT cartsys DOT com
- Raw text -