Basil Hussain wrote on 2021-06-25 21:01:
Personally, my comments are that I think the proposed new calling convention will make life difficult when writing assembly code that is to be called by C code. In my opinion, the current STM8 calling convention suits that scenario just fine.
In my experience when you want to write pure assembly to be called from C it is best to write a dummy C function and compile that into asm as a template from which you can then create your own. Not having ever used stm8, I wonder if the calling convention is properly documented in the comments of the generated assembly for stm8. That would really help the assembly programmer (and the occasional asm output reader).
Currently, where all arguments are on the stack, this gives more flexibility to use A/X/Y registers however one wants, and the function arguments are always there when you need them, without worrying about overwriting or preserving them. With the new convention, one typically would have to push A/X onto the stack immediately, and then use the values from there. If the aim is to reduce stack usage, then it would seem to be counter-productive in this respect. I can see a little benefit of having the first 8/16-bit argument passed in A/X, as you may want to immediately operate on the argument value anyway (a lot of my assembly immediately does "ld a, (3,sp)" or "ldw x, (3,sp)" - you'd save that operation), but it's troublesome in that if you want to refer again to the argument value later, you would have needed to have saved it yourself. Any benefit will probably only be for the most trivial of single-argument functions.
When the function is called in multiple places you probably get smaller code size when the callee pushes the parameter(s) to stack. Maarten _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user