CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

Procedures


  1. CALL and RET Instructions
  2. The PROC Procedures
  3. Defining Procedures
  4. PROC Directive Format
  5. Passing Arguments on the Stack
  6. __cdecl, the C-style calling convention
  7. PASCAL-style and STDCALL calling conventions
  8. C-style Procedure Call Example
  9. Calling Conventions Summary
  10. PASCAL-style Procedure Stack Maintenance
  11. C-style Caller and Callee Summary
  12. STDCALL Caller and Callee Summary
  13. FASTCALL Caller and Callee Summary
  14. Parameter Declarations
  15. ENTER and LEAVE commands
  16. The RET Instruction
  17. Declaring Parameters with the PROC Directive
  18. Pointer Arguments
  19. Local Variables and EBP, Base Pointer Access to Stack
  20. Automated Local Variables
  21. The LOCAL directive
  22. Local Variable Initialization
  23. Procedure Prototypes
  24. PROTO Directive
  25. Prototype Structure
  26. Calling Procedures with INVOKE
  27. Passing an Address Argument

1. CALL and RET Instructions



2. The PROC Procedures



3. Defining Procedures



4. PROC Directive Format



5. Passing Arguments on the Stack



6. __cdecl, the C-style calling convention



7. PASCAL-style and STDCALL calling conventions



8. C-style Procedure Call Example



9. Calling Conventions Summary

Calling Convention Argument Passing Stack Maintenance Name Decoration Notes
__cdecl Right to left. Caller removes arguments from the stack. This calling convention is the only one that allows variable argument lists. Underscore prefixed to function names, as in _Foo. C convention. The default for C and C++ functions.
__stdcall Right to left. Callee removes its own arguments from the stack. Underscore prefixed to function name, and @ appended followed by the decimal number of bytes in the argument list, as in _Foo@12. Standard call. Used by almost all system functions; the default for Visual Basic internal functions.
pascal Left to right. Callee removes its own arguments from the stack. Undecorated symbol name in uppercase letters, as in FOO. The convention adopted in Pascal.
__fastcall First three DWORD parameters are passed in EAX, EDX, and ECX. If these registers are not sufficient for passing all parameters, then the remaining parameters are passed on the stack, right to left. Callee removes its own arguments from the stack. An @ is prefixed to the name, and @ is appended followed by the number of decimal bytes in the argument list, as in @Foo@12. Aka register, or fast calling convention. Applies only to Intel CPUs. This calling convention is the default for Borland Delphi compilers.
this Right to left. The this parameter is passed in the ECX register. Caller removes arguments from the stack. None. Used automatically by C++ class methods unless you specify standard call. COM methods are declared as standard call.
naked Right to left. Caller removes arguments from the stack. None. Used when you need custom prolog and epilog.

10. PASCAL-style Procedure Stack Maintenance


A mismatch in calling convention is catastrophic for a running program.

11. C-style Caller and Callee Summary



12. STDCALL Caller and Callee Summary



13. FASTCALL Caller and Callee Summary



14. Parameter Declarations



15. ENTER and LEAVE commands


  • Command ENTER at the starting point of the procedure,

        ENTER N, O
    

    translates to

        push ebp
        mov ebp, esp
        sub esp, N
    
  • Its corresponding counterpart, the LEAVE command, translates to

        mov esp, ebp
        pop ebp
    
  •   stack before and after the procedure call


16. The RET Instruction



17. Declaring Parameters with the PROC Directive



18. Pointer Arguments



19. Local Variables and EBP, Base Pointer Access to Stack



20. Automated Local Variables



21. The LOCAL directive



22. Local Variable Initialization



23. Procedure Prototypes



24. PROTO Directive



25. Prototype Structure



26. Calling Procedures with INVOKE



27. Passing an Address Argument