cancel
Showing results for 
Search instead for 
Did you mean: 

Parameter sizes in function calls

John Hite
Associate III
Posted on June 09, 2017 at 18:02

I used to hear that one might as well make function parameter ints or the native size as chars and shorts would be promoted before going on the stack.

But now we have fast variables, etc. Does it still make a difference?

Thanks,

jh

2 REPLIES 2
S.Ma
Principal
Posted on June 09, 2017 at 20:44

Well, all these compiler optimisations can be observed in debugger mode assembly window.

For speed, there are many factors to look into such as core pipeline, interrupt vectors in RAM, ISR in RAM, flash wait states, etc... 

For reentrancy, I like function passing a struct pointer to try to stick to a single passing parameter as much as possible, and returning a u32 quantity.

Posted on June 10, 2017 at 00:53

Check ARM ABI

Basically the first four parameter words pass in registers R0..R3 which are 32-bit, and you can get a 32 or 64-bit result in R0,R1. Additional parameter words will be stacked, local/auto variable will either be on the stack or in registers. If you generate an address-of, then the variable will need to be in memory.

The compiler manages working registers and pushes/preserves R4..Rx, pushes LR if you call any other subroutines.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..