#include <stdio.h>
int main() {
float arg1, arg2, add, sub, mul, div ;
printf( "Enter two numbers : " );
scanf( "%f%f", &arg1, &arg2 );
/* Perform floating point Addition, Subtraction, Multiplication & Division */
__asm__ ( "fld %1;"
"fld %2;"
"fadd;"
"fstp %0;" : "=g" (add) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %2;"
"fld %1;"
"fsub;"
"fstp %0;" : "=g" (sub) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %1;"
"fld %2;"
"fmul;"
"fstp %0;" : "=g" (mul) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %2;"
"fld %1;"
"fdiv;"
"fstp %0;" : "=g" (div) : "g" (arg1), "g" (arg2) ) ;
printf( "%f + %f = %f\n", arg1, arg2, add );
printf( "%f - %f = %f\n", arg1, arg2, sub );
printf( "%f * %f = %f\n", arg1, arg2, mul );
printf( "%f / %f = %f\n", arg1, arg2, div );
return 0 ;
}
but when i take the suffix's out as in the next bit of code, the program crashes,
#include <stdio.h>
int main() {
float arg1, arg2, add, sub, mul, div ;
printf( "Enter two numbers : " );
scanf( "%f%f", &arg1, &arg2 );
/* Perform floating point Addition, Subtraction, Multiplication & Division */
__asm__ ( "fld %1;"
"fld %2;"
"fadd;"
"fstp 0;" : "=g" (add) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %2;"
"fld %1;"
"fsub;"
"fstp 0;" : "=g" (sub) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %1;"
"fld %2;"
"fmul;"
"fstp 0;" : "=g" (mul) : "g" (arg1), "g" (arg2) ) ;
__asm__ ( "fld %2;"
"fld %1;"
"fdiv;"
"fstp 0;" : "=g" (div) : "g" (arg1), "g" (arg2) ) ;
printf( "%f + %f = %f\n", arg1, arg2, add );
printf( "%f - %f = %f\n", arg1, arg2, sub );
printf( "%f * %f = %f\n", arg1, arg2, mul );
printf( "%f / %f = %f\n", arg1, arg2, div );
return 0 ;
}
i'm guessing this is a very situation based issue(what i'm using to compile and on what system) so i'm using code::blocks with the GNU GCC compiler running windows vista with and AMD proc, i know very little about asm (very little, extremely little) i am however very interested in the subject, but due to my extremely limited understanding of the topic i would be ok with someone who has better incite on the topic telling me to wait until some other point.
This post has been edited by ishkabible: 28 June 2010 - 01:55 PM

New Topic/Question
Reply







MultiQuote






|