### _System Calling Convention in OS/2

To use this convention, you must use the _System keyword in the declaration of the function or set the /Ms compiler option.

Note: Because the IBM C and C++ Compilers library functions use the _Optlink convention, if you use the /Ms compiler option, you must include all appropriate library header files to ensure the functions are called with the correct convention.

The following rules apply to the _System calling convention:

- All parameters are passed on the run-time stack.
- The C parameter-passing convention is followed, where parameters are pushed onto the stack in right-to-left order.
- The calling function is responsible for removing parameters from the stack.
- All parameters are doubleword (4-byte) aligned.
- The size of the parameter list is passed in AL. If the __parmdwords function parameter list is greater than 255 doublewords, the value contained in AL is the 8 least significant bits of the size. You can use the __parmdwords function to access the value of AL that was passed to the function.

  Note: The __parmdwords function may not yield the correct value in the case of compilers that do not follow the rule of passing the size of the parameter list in AL. You can use the __parmdwords function with code compiled under IBM C and C++ Compilers for OS/2 provided the code was compiled with the /Gp+ compiler option.

- Floating point values are returned in ST(0), the top register of the floating point register stack. Functions returning non-floating point values return them as follows:
  Size of Aggregate
    Value Returned in
  8 bytes
    EAX-EDX pair
  5, 6, 7 bytes
    EAX The address to place the return values is passed as a hidden parameter in EAX.
  4 bytes
    EAX
  3 bytes
    EAX The address to place the return values is passed as a hidden parameter to EAX.
  2 bytes
    AX
  1 byte
    AL
- All functions preserve the general purpose registers of the caller, _System convention except for ECX, EDX, and EAX.
- Structures passed by value are actually copied onto the stack, not passed by reference.
- The floating-point stack is defined to be empty upon entry to a called function, and has either a single item in ST(0) if there is a floating-point return, or is empty if there is not a floating-point return.
- The direction flag must be clear upon entry to functions and clear on exit from functions. The state of the other flags is ignored on entry to a function, and undefined on exit.
- The compiler will not change the contents of the floating-point control register. If you want to change the control register contents for a particular operation, save the contents before making the changes and restore them after the operation.

Calling Conventions

Examples Using the _System Calling Convention in OS/2
_System Calling Convention in Windows