Jennifer Q
Jennifer Q

Reputation: 369

Does the C ABI require arguments to be passed to functions using the stack?

Does the C ABI require arguments to always be passed to functions using only the stack?

Upvotes: 0

Views: 1680

Answers (2)

a3.14_Infinity
a3.14_Infinity

Reputation: 5851

ABI or Application Binary Interface covers various details in the contract between pieces of binary code.

  • (A broad definition) - It defines the mechanisms by which functions are invoked, how parameters are passed between caller and callee, how return values are provided to callers, how libraries are implemented, and how programs are loaded into memory.

  • (Specifically) the calling convention, which controls how functions' arguments are passed and return values retrieved; for example, whether all parameters are passed on the stack or some are passed in registers, which registers are used for which function parameters, and whether the first function parameter passed on the stack is pushed first or last onto the stack.

  • A live example - refer to calling convention mentioned by ARM ABI Procedure Call Standard for ARM Architecture - you may refer to section on Stack (end of page 16) - The stack is a contiguous area of memory that may be used for storage of local variables and for passing additional arguments to subroutines when there are insufficient argument registers available

Upvotes: 4

Nick
Nick

Reputation: 5

Yes, arguments to functions are always passed using the stack. This is why if you are going to be passing something large, it is advisable to pass a pointer to avoid a stack overflow.

Upvotes: -2

Related Questions