Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Parameters in 64 bit Assembly Function from C language. Which Register Receive These Parameter?

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?

like image 211
user2365346 Avatar asked May 09 '13 07:05

user2365346


People also ask

Which registers are used for 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.

How many arguments are passed using registers?

When one C function calls another, only the first four arguments to the called function are passed in registers.

How do you pass a parameter in assembly code?

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.

What are the parameter passing techniques in C++?

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”.

How to pass parameters from calling function to called function in C?

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.

Where do I pass the first few parameters in 64-bit code?

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.


2 Answers

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.

like image 29
Timothy Baldwin Avatar answered Nov 15 '22 00:11

Timothy Baldwin


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).

like image 150
Drew McGowen Avatar answered Nov 14 '22 23:11

Drew McGowen