gcc and asm keyword

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
i am writing a test code using asm keyword.

int fun(int in)
{
 int b=2;
asm("movl $100, %0;"
    "test %1, %1;"
    "cmovl %1, %0;"
    : "=r" (b)
    : "r" (in)
    );
return b;
}

int main()
{
int a=8;
int b;

b = fun(-1);
printf("%d %d\n",a,b);
}
the output of above code should be "8 -1", ie the value of "b" in main after
calling "fun" should be "-1". instead the output is "8 100"


the assemble output is
fun:
  pushl %ebp
  movl  %esp, %ebp
  subl  $16, %esp
  movl  $2, -4(%ebp)
  movl  8(%ebp), %eax
#APP
# 6 "asm.c" 1
  movl $100, %eax;test %eax, %eax;cmovl %eax, %eax;
# 0 "" 2
#NO_APP
  movl  %eax, -4(%ebp)
  movl  -4(%ebp), %eax
  leave
  ret

my main motto of writing this code was to test the "cvmol" instruction.
so basically whenever the test instruction will show that the result is less
than 0, the "cmov" instruction should move the data

i used the mov instruction so that initially 100 gets moved into variable
"b" and if the test ins indicate the input value is -ve, cmov instruction
should move the input value to the variable "b"

just check the assembly code that gcc is generating, gcc is using eax for
both %0 and %1
due to which the code is giving wrong result
-- 
View this message in context: http://www.nabble.com/gcc-and-asm-keyword-tp25530602p25530602.html
Sent from the gcc - Help mailing list archive at Nabble.com.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux