Page 1 of 1

Procedure Calling Convention

Posted: Fri May 03, 2024 1:44 am
by gray
The ARM Architecture Procedure Call Standard (AAPCS) stipulates that, upon calling a procedure
1) registers r0 to r3, and r12, are "caller saved", ie. the called procedure is free to mutate them.
2) registers r4 to r11 are "callee saved", ie. the called procedure must save and restore these registers in case it mutates them.
Parameters are passed via r0 to r3, and the stack if needed.

The Astrobe compiler saves all register before calling a procedure, ie. all registers are "caller saved", and passes all parameters in registers.[1]

Just out of interest: is there a rule or convention, explicit or tacit, regarding this behaviour for Oberon programs?

[1] Exception handlers behave like the above standard regarding register saving and restoring, based on the exception handler implementation in the Cortex-M MCUs (stacking of r0 to r3 and r12).

Re: Procedure Calling Convention

Posted: Sat May 04, 2024 2:34 am
by cfbsoftware
An Oberon Compiler for the ARM Processor is a detailed description of the architecture of Niklaus Wirth's ARM Oberon compiler that we used as the basis for our first Astrobe (a.k.a Armaide) ARM compilers in 2008.

Note that the parameter passing convention is dependent on whether a procedure is declared as a "leaf" procedure or not. Refer to Chapter 22 for details.

The register allocation and parameter passing convention that is described was used in Astrobe for Cortex-M3, M4 and M7 until Aug 2023 when v9 was released. With the introduction of Astrobe for Cortex-M0 the register allocation, and consequently, the parameter passing convention was changed as summarised in the latest Whats New in Astrobe notes.

Recommended related further reading is Wirth's Compiler Construction book which you can download from:

https://www.astrobe.com/wirth/CompilerConstruction.pdf