Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread alan
On Fri, 21 Oct 2022 20:31:52 +0300 Ori Idan wrote: > 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. Not since 1989. ANSI C distinguishes between p

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread Philipp Klaus Krause
Am 21.10.22 um 19:31 schrieb Ori Idan: 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. In C (the programming language), there are functions declared w

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread Philipp Klaus Krause
Am 21.10.22 um 16:43 schrieb Basil Hussain: 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 c

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread Ori Idan
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 Huss

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread Basil Hussain
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,

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-21 Thread Philipp Klaus Krause
I don't have time to check now, but wonder if that addw    sp, #12 should have been addw    sp, #14 instead No, 12 should be fine fine: 4 for x and y each, 2 for z, 2 for the return address. ___ Sdcc-user mailing list Sdcc-user@lists.sourceforg

Re: [Sdcc-user] Bad code generated having no SP rewind after function call

2022-10-20 Thread Philipp Klaus Krause
> For some reason, in a certain scenario it is not rewinding the stack > pointer after returning from a function call. That is, before the > function call, it pushes arguments to the stack as normal, but > afterwards it is NOT following up with a "addw sp, #N" instruction. The cleanup for stack p