Reputation: 1813
Is there a way to force gcc to pass the parameters of a function on the stack?
I don't want to use the registers for parameter passing.
Update: I'am using arm-gcc from CodeSourcery
Upvotes: 8
Views: 4618
Reputation: 11
Where to store a local variable is depend on how you will use it. If you need to get a local variable's address, the local variable can only be stored on the stack. So when you pass your subroutine a pointer, this parameter will be passed through the stack.
Upvotes: 0
Reputation: 28320
You can try wrapping the parameters in a structure; for example, if your function is int calc_my_sum(int x, int y) {return x+y;}
you can change it as follows (ugly):
struct my_x_y {
int x, y;
my_x_y(): x(0), y(0) {} // a non-trivial constructor to make the type non-POD
};
int calc_my_sum(my_x_y x_and_y) {
// passing non-POD object by value forces to use the stack
return x_and_y.x + x_and_y.y;
}
Alternatively, you can just add 4 dummy parameters to use up the registers, so other parameters will use stack:
struct force_stack_usage {
int dummy0, dummy1, dummy2, dummy3;
}
int calc_my_sum(force_stack_usage, int x, int y) {
return x + y;
}
Upvotes: 2
Reputation:
According to: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf
The first four registers r0-r3 (a1-a4) are used to pass argument values into a subroutine and to return a result value from a function. They may also be used to hold intermediate values within a routine (but, in general, only between subroutine calls).
There are, on ARM, no other calling conventions but the default, that I know of. And here is why:
Upvotes: 0