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?
Argument registers (X0-X7) These are used to pass parameters to a function and to return a result. They can be used as scratch registers or as caller-saved register variables that can hold intermediate values within a function, between calls to other functions.
When one C function calls another, only the first four arguments to the called function are passed in registers.
Passing Parameters in Assembly In 64-bit x86 code, you pass the first few parameters in registers. Annoyingly, exactly which registers you use depends on the machine: On x86-64 UNIX systems,including Linux and default NetRun, the first six parameters go into rdi, rsi, rdx, rcx, r8, and r9.
Parameter Passing Techniques in C/C++. There are different ways in which parameter data can be passed into and out of methods and functions. Let us assume that a function B() is called from another function A(). In this case A is called the “caller function” and B is called the “called function or callee function”.
In C Programming Language, there are two methods to pass parameters from calling function to called function and they are as follows... Call by Value. In call by value parameter passing method, the copy of actual parameter values are copied to formal parameters and these formal parameters are used in called function.
In 64-bit x86 code, you pass the first few parameters in registers. Annoyingly, exactly which registers you use depends on the machine: On x86-64 UNIX systems,including Linux and default NetRun, the first six parameters go into rdi, rsi, rdx, rcx, r8, and r9. On Windows 64, the first four parameters go into rcx, rdx, r8, and r9.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With