|
To meet Wikipedia's quality standards, this article or section may require cleanup. Please discuss this issue on the talk page, or replace this tag with a more specific message. Editing help is available. This article has been tagged since October 2005. A calling convention is a method for a programming language to send data to a function, and receive data back from functions. When writing a piece of software in multiple languages and modules, it is necessary for all modules to use compatible calling conventions. Computer code (HTML with JavaScript) in a tool that uses syntax highlighting (colors) to help the developer see the purpose of each piece of code. ...
In computer science, a subroutine (function, procedure, or subprogram) is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one, or more, statement blocks; such code is sometimes collected into software libraries. ...
Computer software (or simply software) refers to one or more computer programs and data held in the storage of a computer for some purpose. ...
Calling conventions differ in the order passed parameters are placed on the stack, methods for sending data to a function, receiving return data from a function, and methods of Name mangling. It has been suggested that Name decoration be merged into this article or section. ...
cdecl The cdecl calling convention is used by many C and C++ systems for the x86 architecture. In cdecl, function parameters are passed on the stack in a right-to-left order. Function return values are returned in the EAX register. Registers EAX, ECX, and EDX are available for use in the function. The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use...
For a WikiBook on programming with C++, see Wikibooks: C++ Programming. ...
x86 or 80x86 is the generic name of a microprocessor architecture first developed and manufactured by Intel. ...
In computer science, a call stack is a special stack which stores information about the active subroutines of a computer program. ...
In computer architecture, a processor register is a small amount of very fast computer memory used to speed the execution of computer programs by providing quick access to commonly used values—typically, the values being in the midst of a calculation at a given point in time. ...
For instance, the following C code function prototype and function call: The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use...
int function(int, int, int); int a, b, c, x; ... x = function(a, b, c); will produce the following x86 Assembly code (written in MASM syntax): Wikibooks has more about this subject: Programming:x86 assembly x86 assembly language is the assembly language for the x86 class of processors, which includes Intels Pentium series and AMDs Athlon series. ...
The Microsoft Macro Assembler (MASM) is a high-level assembler that was produced by Microsoft. ...
push c push b push a call function add esp, 12 ;Stack clearing mov x, eax The calling function cleans the stack after the function call returns. The cdecl calling convention is usually the default calling convention for x86 C compilers, although many compilers provide options to automatically change the calling conventions used. To manually define a function to be cdecl, some support the following syntax: A compiler is a computer program that translates a computer program written in one computer language (called the source language) into an equivalent program written in another computer language (called the output or the target language). ...
void _cdecl function(params); The _cdecl modifier must be included in the function prototype, and in the function declaration to override any other settings that might be in place.
Pascal The Pascal calling convention is the reverse of the C calling convention. The parameters are pushed on the stack in left-to-right order and the callee is responsible for balancing the stack before return. Pascal is an imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming. ...
The callee balances the stack by the assembly code: "ret freestack", where freestack is a constant integer.
Register (FastCall) The Register or FastCall calling convention is compiler-specific; for specific information, consult the compiler's documentation. In general, however, the register calling convention states that the first 2 or 3 function arguments with a size of 32 bits or lower will be passed in the EAX, EDX, and possibly ECX registers instead of on the stack. The remaining arguments are passed right-to-left on the stack similar to cdecl. Return values are passed in the AL, AX, or EAX register.
stdcall The stdcall[1] calling convention is the de facto standard calling convention for Microsoft Windows NT programming API. Function parameters are passed Right-to-Left. Registers EAX, ECX, and EDX are preserved for use within the function. Return values are stored in the EAX register. Unlike cdecl, the called function cleans the stack, instead of the calling function. Because of this fact, stdcall functions cannot support variable-length argument lists. Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. ...
An application programming interface (API) is the interface that a computer system, library or application provides in order to allow requests for service to be made of it by other computer programs, and/or to allow data to be exchanged between them. ...
On a Microsoft Windows system, a function may be declared to be stdcall using the following syntax in the function prototype, and in the function declaration: As of 2006, Microsoft Windows is the worlds most popular operating system for use on personal computers. ...
void __stdcall function(params); Stdcall functions are easy to recognize in ASM code because those functions will all unwind the stack prior to returning. the x86 ret instruction allows an optional byte parameter that specifies the number of stack locations to unwind before returning to the caller. such code looks like this: ret 14 safecall In Borland Delphi on Microsoft Windows, the safecall calling convention encapsulates COM (Component Object Model) error handling, so that exceptions aren't leaked out to the caller, but are reported in the HRESULT return value, as required by COM/OLE. When calling a safecall function from Delphi code, Delphi also automatically checks the returned HRESULT and raises an exception if necessary. Together with language-level support for COM interfaces and automatic IUnknown handling (implicit AddRef/Release/QueryInterface calls), the safecall calling convention makes COM/OLE programming in Delphi very nice and elegant. Delphi has been released in many versions, including older versions which have been released in magazines for non-profit application use Borland Delphi is software development package created by Borland. ...
As of 2006, Microsoft Windows is the worlds most popular operating system for use on personal computers. ...
Component Object Model (COM) is a Microsoft platform for software componentry introduced by Microsoft in 1993. ...
thiscall This calling convention is used for calling C++ member functions. There are two primary versions of thiscall used depending on the compiler and whether or not the function uses variable arguments. For the GCC compiler, thiscall is almost identical to cdecl: the calling function cleans the stack, and the parameters are passed in right-to-left order. The difference is the addition of the this pointer, which is pushed onto the stack last, after all the parameters. This is the same method used by Windows thiscall functions that use variable arguments. Windows functions that do not use variable arguments also have their arguments passed in right-to-left order, but the called function cleans the stack and the this pointer is passed in the ECX register. The thiscall calling convention cannot be explicitly specified as thiscall is not a keyword.
Intel ABI The Intel Application Binary Interface is a computer programming standard that most compilers and languages follow. According to the Intel ABI, the EAX, EDX, and ECX are to be free for use within a procedure or function, and need not be preserved. Intel Corporation (NASDAQ: INTC, SEHK: 4335), founded in 1968 as Integrated Electronics Corporation, is a U.S.-based multinational corporation that is best known for designing and manufacturing microprocessors and specialized integrated circuits. ...
In computer software, an application binary interface (ABI) describes the low-level interface between an application program and the operating system, between an application and its libraries, or between component parts of the application. ...
Microsoft x64 calling convention The x64 calling convention takes advantage of additional register space in the x86-64 / Intel EM64T platform. Parameters are passed into RCX, RDX, R8, R9 (in that order). Additional arguments are pushed onto the stack. The return value is stored in RAX. x64 is Microsoft Corporations marketing designation for the Advanced Micro Devices AMD64 and Intel EM64T 64-bit Instruction Set Extensions to the x86 architecture, which were substantially similar as of 2004. ...
The AMD64 or x86-64 is a 64-bit processor architecture invented by AMD. It is a superset of the x86 architecture, which it natively supports. ...
Extended Memory 64-bit Technology (EM64T) is Intels implementation of AMD64, a 64-bit extension to the IA-32 architecture. ...
Standard Exit and Entry Sequences The standard entry sequence to a function is as follows: _function: push ebp ;store the old base pointer mov ebp, esp ;make the base pointer point to the current stack location ;which is where the parameters are sub esp, x ;x is the size, in bytes, of all "automatic variables" ;in the function This sequence preserves the original base pointer ebp, points ebp to the location of the function parameters on the stack, and creates space for automatic variables on the stack. Local variables are created on the stack with each call to the function, and are cleaned up at the end of each function. This behavior allows for functions to be called recursively. In C and C++, variables declared "automatic" are created in this way. In computer science, a local variable is a variable that is given local scope. ...
It has been suggested that this article or section be merged into computable function. ...
The Standard Exit Sequence goes as follows: mov esp, ebp ;reset the stack to "clean" away the local variables pop ebp ;restore the original base pointer ret ;return from the function The following C function: int _cdecl MyFunction(int i){ int k; return i + k; } would produce the equivalent asm code: ;entry sequence push ebp mov ebp, esp sub esp, 4 ;create space for "int k" ;function code mov eax, [ebp + 8] ;move parameter i to accumulator add eax, [ebp - 4] ;add k to i ;answer is returned in eax ;exit sequence mov esp, ebp pop ebp ret See also In computer software, an application binary interface (ABI) describes the low-level interface between an application program and the operating system, between an application and its libraries, or between component parts of the application. ...
External links |