Passing parameters between functions using the GNUPro Compiler Tools.

Question: How does the GNUPro Compiler pass parameters to and from assembly code?

 

Answer:

The manner in which parameters are passed between functions depends on the amount of information being passed. For the first six parameters that are passed by the calling functions, they are passed in the registers r0, r1, r2, r3, r4, r5. If there are additional parameters beyond this, the additional parameters will be passed by being pushed onto the stack. If the function that is called is going to returning a 16-bit value, the function will return the value in the register r0. If the called function is returning only an 8-bit value, the value will be returned in the LSB of register R0. If the called function is returning a 32-bit value, the value will be returned in the registers r1 and r0, where r1 will contain the LSW and register r0 will contain the MSW. If you were to return a structure (this is bad practice) space is allocated on the stack and a pointer to the stack area is returned. The calling function will contain code to release the used stack memory upon completion. Keywords: GNUPro Compiler, passing parameters between C+ and assembly ID: KKU03091701