Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

a) Return address is passed in the "link register" - our call instruction is "bl" (branch and link) and return is "blr" (branch link register)

b) We have 32 general purpose registers - the ABI defines a certain range of registers (8 general purpose registers + a bunch of floating point and vector registers) for passing parameters

c) The register range allocated for passing parameters is designated as "volatile", so the caller can't rely on them coming back unmodified. This gives you a few registers to play with.

(NB: I'm not hugely experienced in PPC assembly programming, I've just had to touch it a couple of times and so I've read bits and pieces of the ABI, don't trust what I say here...)



Aha, but if you have at least function 2 calls, assuming none is inlined, you HAVE to use the stack to save the prev LR. I actually think it's one of the default processes at the beginning of a function, but maybe the compiler optimizes in many cases.. I'm really curious if you can find some assembly examples of functions where you don't use the stack. I've seen it on Renesas MCU's and on PPC but only for veery simple functions.

Also, the architecture isn't exactly the one to blame for this, it's more dependant on compiler calling conventions. I see things in the arch that facillitate this, but I see it possible to implement this mechanism with or without this arch support. I've only seen certain registers being reserved for something in the compiler docs not the MCU docs.

Eh, maybe I'm rambling.


Oh, yeah, only for leaf functions. Obviously not for multiple levels of calls.

My understanding is that PPC encourages register based parameter passing just by virtue of having a tonne of registers.


Nope, non-leaf functions don't really need a stack. Normal compilers will do it, but there are plenty of registers that can be used instead.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: