6
votes

I want to pass a parameter to an assembly function from C.

On a UNIX-like system, the first six parameters go into rdi, rsi, rdx, rcx, r8, and r9.

On Windows, the first four parameters go into rcx, rdx, r8, and r9.

Now, my question is: On the BIOS- or DOS programming level, which registers receive these parameters? If the number of parameter are more than 6, how do I write the assembly to handle these parameters?

2
if you need such a control over where your parameters go (in which register) from C to interface properly with a "custom" function (which complies to its own calling convention), likely you need to use some special feature of your compiler. When registers are not enough, likely stack is what you need (or one register pointing to the "array" of argumetns) (see e.g. en.wikipedia.org/wiki/X86_calling_conventions )ShinTakezou
Perhaps, using asmlinkage and pass arg through stack.rakib_

2 Answers

2
votes

If I understand the first part of your question, using C in 16-bit mode is not really supported (since 16-bit mode uses segmentation to get past 16 bits of addressing).

Referring to the second part, that depends on the compiler, but IIRC both Windows and Unix will pass additional arguments on the stack (see http://en.wikipedia.org/wiki/X86_calling_conventions for more on argument passing).

2
votes

64-bit UEFI uses the Windows convention.

The BIOS and DOS APIs are defined in assembly language.

Traditionally in 16-bit and 32-bit x86 all the arguments are stored on the stack.