Page 1 of 1

c and assembly problem

Posted: Wed Jan 25, 2012 3:40 pm
by huh
I write my os mostly in c, but sometimes I NEED to use assembly. if i define a variable in c:

Code: Select all

main()
{
  long var = 0;
}
and then i want to do something with it in assembly:

Code: Select all

asm("movl $1, var\n");
the gcc compiler gives me this error:

Code: Select all

/tmp/ccpKcN36.o: In function `main':
test.c:(.text+0xf): undefined reference to `var'
collect2: ld returned 1 exit status
why?

Re: c and assembly problem

Posted: Wed Jan 25, 2012 4:51 pm
by bubach
The wiki has a section about inline assembly, and examples of correct syntax:
http://wiki.osdev.org/Inline_Assembly

Re: c and assembly problem

Posted: Fri Jan 27, 2012 9:51 am
by qw
This is GCC specific. In MSVC it is perfectly valid to use local variable names in inline assembly directly. This is mainly a matter of syntax.