Author: Anthony Cozzie
Date: 06:23:01 05/21/04
Go up one level in this thread
On May 21, 2004 at 09:15:36, Christophe Drieu wrote:
>Hi, i'm learning Inline assembly with gcc, but have some trouble with global C
>variables:
>
>int a=4, b=0;
>
>int main()
>{
> asm("incl _a"); // a++
> asm("movl _a,%eax"); // eax=a
> asm("movl %eax,_b"); // b=eax
>
> printf("a=%d b=%d\n", a, b); // print a=5 b=5
>
> a=4;
>
> asm("incl _a"); // a++
> asm("movl _a,%eax"); // eax=a
> asm("movl %eax,_b"); // b=eax
>
> printf("a=%d b=%d\n", a, b); // print a=4 b=5
>}
>
>My question is, why a==4 in second case and not 5 ? Thank you.
Dunno if this is the issue, but registers are not guaranteed to be preserved
between asm calls.
gcc -S will show you the actual assembly that is generated - I'd take a look at
that.
This is my personal inline assembly reference:
http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html
anthony
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.