I am not familiar with how SDCC does it but in C calling convention the
function does not have to know the number of parameters, therefore can not
adjust the stack. Only the caller can do it.

-- 
Ori Idan CEO Helicon Books
http://www.heliconbooks.com





On Fri, Oct 21, 2022 at 6:00 PM Basil Hussain <ba...@stasisleak.uk> wrote:

> On 21/10/2022 07:44, Philipp Klaus Krause wrote:
> > The cleanup for stack parameters is done for both: for foo by the
> > callee, for bar by the caller. Which one does it depends on the type
> > of the function. For details, see section 4.5.1.1, "SDCC calling
> > convention, version 1" in the manual:
>
> Argh, $*!% me, I did not notice this was the case. I usually work with
> large memory model STM8 devices, but this is for a medium-only device,
> and the void-returning function meets the criteria for callee stack
> adjustment. >:(
>
> Can you briefly remind me what is the rationale behind void-returning
> functions having the stack clean-up done by caller and not callee? One
> of the things I prefer about the old calling convention is that it's
> just so much simpler, without exceptions like this.
>
> Now I understand why 'i' was being trampled, as in my original code
> function 'foo' is in fact a __naked inline assembly function, where I am
> not cleaning the function arguments from the stack.
>
> Regards,
> Basil Hussain
>
> P.S. By the way, now I am looking at the manual again, is there not a
> mistake in section 4.5.1.2 describing calling convention version 0? It
> says:
>
> > All parameters are passed on the stack. The stack is not adjusted for
> > the parameters after the call (thus the callee has to do this
> > instead), unless __z88dk_callee is specified.
>
> The second sentence is self-contradicting. Callee must adjust the stack,
> unless you specify the option that says the callee will adjust the
> stack!? I have never encountered functions that are attributed as
> version 0 and SDCC does *not* generate stack rewind after calls to them
> (i.e. caller SP rewind, not callee).
>
>
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to