D
D
Danil Tunev2018-10-19 10:48:42
C++ / C#
Danil Tunev, 2018-10-19 10:48:42

How to pass multiple parameters from C to a function in assembler?

More interesting is not how to pass several parameters, but by what means to get them in a function on the assembler? Here is a function prototype int func(int*,int,char); I get the first parameter, an array of int type, through %ebx and I can return the value from the function through %eax, but what about the rest of the arguments following the first parameter in the function, through which registers? And how to get access to the global variables of the Cish program?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-10-19
@lada-guy

For the AMD64 architecture on Linux, the System V AMD64 ABI is used :
The first 6 integers or pointers are passed in the RDI, RSI, RDX, RCX, R8, R9 registers, and the floating point numbers in the XMM0, XMM1, XMM2, XMM3, XMM4, XMM5 registers , XMM6 and XMM7. If there are more parameters, then additional ones are passed through the stack. Integers up to 64-bit are returned in the RAX register, and larger ones in the RAX and RDX register pair. Floating point numbers are similarly returned in the XMM0 and XMM1 registers.

F
freeExec, 2018-10-19
@freeExec

The first few parameters are passed through registers, the rest through the stack.
https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
C has transfer standards, but in your assemblers you are free to cast as you please.
https://msdn.microsoft.com/en-us/library/zkwh89ks.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question