2

The following inline assemble code is not working on my system. What is the problem with that code?

If I use asm instead of __asm__ then it works properly.

#include <stdio.h>

int main() {

    float arg1, arg2, div ;

    printf( "Enter two numbers : " );
    scanf( "%f%f", &arg1, &arg2 );

    /* Perform floating Division */


    __asm__ ( "fld %2;"
              "fld %1;"
              "fdiv;"
              "fstp %0;" : "=g" (div) : "g" (arg1), "g" (arg2) ) ;

    printf( "%f / %f = %f\n", arg1, arg2, div );

    return 0 ;
}
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Singh123
  • 216
  • 3
  • 10
  • Does the source file name end with `.c` or with `.cpp` ? In other words, are you compiling this as C or as C++ ? – Paul R Jul 19 '14 at 08:18
  • source file name end with .cpp – Singh123 Jul 19 '14 at 08:23
  • what compiler are you using? – It'sPete Jul 19 '14 at 08:26
  • If the extension is .cpp then it is compiled as C++, the title and tag were therefore misleading - edited. – Clifford Jul 19 '14 at 08:30
  • 1
    It compiles fine at https://ideone.com in C, C++ 4.8.1 and C++11 compilation modes. What error message are you actually getting? What compiler options have you selected? `asm` is a reserved keyword in ISO C++, but not in ISO C, `__asm__` [should work in both](https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/Alternate-Keywords.html#Alternate-Keywords). If you use the `-pedantic` option you kind of get what you deserve - nobody likes a pedant!. – Clifford Jul 19 '14 at 08:42
  • 3
    "Doesn't work" is not a suitable description of any problem. What does it do, what do you expect? – Ulrich Eckhardt Jul 19 '14 at 08:50
  • did you picked a version for your language like `-std=c99` ? – user2485710 Jul 19 '14 at 09:12
  • it compiles fine with tc++ windows .thanks @clifford. – Singh123 Jul 19 '14 at 09:17
  • @LeventeKurusa : You can delete your own comments you know? – Clifford Jul 19 '14 at 11:32
  • @Atuljssaten : My comment was a request for you to improve the question by adding necessary information - that would be fare more useful that a thanks (I am not even sure what you are thanking me for). I really hope you are not referring to Turbo C++? – Clifford Jul 19 '14 at 11:35

0 Answers0