Question

I am learning PPC Assembly but am having a hard time understanding the following about sub routine calls:

What registers can be used to pass arguments to a sub routine? I think it is R3 to R12? How do you pass arguments when you run out of registers? Could I please see a code example of this.

When passing back return values, can you only use R3? From what I understand you can only use this register to return a single value. If you need to return more values then you return a pointer to those values? Could I possibly see a code example for this too.

Was it helpful?

Solution

If you're writing in assembly language, you can do whatever you want. It's only when you want to interact with some external code (maybe a library, maybe a system call) that you need to obey the calling convention. Some architectures have multiple different ABIs, so you have to be careful.

If I recall correctly, pretty much everybody uses the same calling convention for 32-bit PowerPC, so this Apple reference should have everything you need to know. As you mention, parameters are commonly passed in R3-R10 and the return value is put in R3. This tutorial seems to indicate the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top