Calling Conventions: Difference between revisions

m
s/dword/uint32_t/g
[unchecked revision][unchecked revision]
(Link to System V ABI and add categories)
m (s/dword/uint32_t/g)
Line 82:
 
==Passing Function Arguments==
GCC/x86 passes function arguments on the stack. These arguments are pushed in reverse order from their order in the argument list. Furthermore, since the x86 protected-mode stack operations operate on doubleword (32-bit) values, the values are always pushed as a doubleword32-bit value, even if the actual value is less than a full doubleword32-bot value. Thus, for function <tt>foo()</tt>, the value of <tt>quux</tt> (a 48-bit FP value) is pushed first as two doublewords32-bit values, low-dword32-bit-value first; the value of <tt>baz</tt> is pushed as the first byte of in doubleword32-bit value; and then finally <tt>bar</tt> is pushed as a doubleword32-bit value.
 
To pass arguments to a C function, the calling function must push the argument values as described above. Thus, to call foo() from a [[NASM]] assembly program, you would do something like this
 
<syntaxhighlight lang="asm">
push eax ; low dword32-bit of quux
push edx ; high dword32-bit of quux
push bl ; baz
push ecx ; bar
Line 104:
mov ecx, [ebp + 8] ; fie
mov bl, [ebp + 12] ; foe
mov edx, [ebp + 16] ; low dword32-bit of fum
mov eax, [ebp + 20] ; high dword32-bit of fum
</syntaxhighlight>
 
Anonymous user