Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - consider the following example. http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Consider the following example.

Example:

     extern  void    myrtn(int,float,double,long int);

     void main()
     {
         float    x;
         double   y;
         int      i;
         long int j;

         x = 7.7;
         i = 7;
         y = 77.77
         j = 77;
         myrtn( i, x, y, j );
     }

myrtn is an assembly language function that requires four arguments.  The
first argument is of type "int" ( 2 bytes), the second argument is of type
"float" (4 bytes), the third argument is of type "double" (8 bytes) and the
fourth argument is of type "long int" (4 bytes).  These arguments will be
passed to myrtn in the following way:

 1. The first argument will be passed in register AX leaving BX, CX and DX
    as available registers for other arguments.

 2. The second argument will be passed on the 80x86 stack since it is a
    floating-point argument.

 3. The third argument will also be passed on the 80x86 stack since it is a
    floating-point argument.

 4. The fourth argument will be passed on the 80x86 stack since a previous
    argument has been assigned a position on the 80x86 stack.

Remember, arguments are pushed on the stack from right to left.  That is,
the rightmost argument is pushed first.

Any assembly language function must obey the following rule.

 1. All arguments passed on the stack must be removed by the called
    function.

The following is a sample assembly language function which implements myrtn.

Example:

             .8087
     _TEXT   segment byte public 'CODE'
             assume  CS:_TEXT
             public  myrtn_
     myrtn_  proc    near
     ;
     ; body of function
     ;
             ret 16           ; return and pop arguments
     myrtn_  endp
     _TEXT   ends
             end

Notes:

 1. Function names must be followed by an underscore.

 2. All used 80x86 registers must be saved on entry and restored on exit
    except those used to pass arguments and return values.  Note that
    segment registers only have to saved and restored if you are compiling
    your application with the "r" option.  In this example, AX does not have
    to be saved as it was used to pass the first argument.  Floating-point
    registers can be modified without saving their contents.

 3. The direction flag must be clear before returning to the caller.

 4. This function has been written for a small code model.  Any segment
    containing executable code must belong to the class "CODE" and the
    segment "_TEXT".  On entry, CS contains the segment address of the
    segment "_TEXT".  The above restrictions do not apply in a big code
    memory model.

 5. When writing assembly language functions for a small code model, you
    must declare them as "near".  If you wish to write assembly language
    functions for a big code model, you must declare them as "far".

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson