Thread: In C. How to retrieve RETURN values from assembly functions? I always got 0

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    16

    In C. How to retrieve RETURN values from assembly functions? I always got 0

    Hello. I have a simply programs that sums two numbers in assembler. I also have a c program with a .h file that must use that program.

    But I always got as a result a 0.

    This is my asm code

    Code:
    Code:
    MyProc proc var1:REAL4, var2:REAL4
        LOCAL retval:REAL4
        PUBLIC MyProc
        finit
        fld var1
        fld var2
        fadd
        fstp retval
        fwait                ;<- is this really needed?
        mov eax, retval
        ret
    MyProc endp
    This is my .h code

    Code:
    Code:
    #ifndef _FLOTANTE_H
    #define _FLOTANTE_H
    
    extern "C" unsigned long __stdcall __MyProc(float, float);
    
    float MyProc(float f1, float f2);
    
    
    #endif

    and this is my C code


    Code:
    Code:
    void sum(void)
    {
         int ch;
         float f1;
         float f2;
         printf("Enter first number\n\n");
    	scanf("%d",&f1);
    	printf("Enter second  number\n\n");
    	scanf("%d",&f2);
         
         float total2;
         total2 = MyProc(f1, f2);
         printf("Total is: %d", total2);
    
    	while ( (ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ( (ch = getchar()) != '\n' && ch != EOF)
    ;
       if(ch=='\n' || ch==EOF)
       {
          printmenu();           
       }
       
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    maybe using the same data types would help........

    what was your input?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    16
    3 and 2 for example

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 10:40 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM