Page 1 of 1

__smallc __naked function with asm - which regs need to be preserved?

Posted: Sun Apr 18, 2021 8:35 pm
by alank2
I think I am using the new compiler, my command line is this:

zcc +cpm -I.. -DPORT_CPM -clib=sdcc_iy -create-app ..\main.c -otest.com

I have a function that get's a character from CP/M:

uint8_t C_RAWIO() __smallc __naked
{
__asm
push ix
ld c,6 //bdos function 0x06
ld e,0xff //bdos parameter return character without echoing
call 5 //call bdos
ld l,a //copy result a into l for return
pop ix
ret
__endasm;
}

It works, but when I wrote this I probably just made it work.

I found these:
https://github.com/z88dk/z88dk/wiki/CallingConventions
https://github.com/z88dk/z88dk/wiki/The-Stack-Frame

But are they relevant for the compiler I am using? I don't think it is the old one.

I'm not sure why I am pushing/popping ix here.

Which registers do I need to preserve? Which ones do I not?

Are there any that need to be saved before a CP/M call?

Re: __smallc __naked function with asm - which regs need to be preserved?

Posted: Sun Apr 18, 2021 9:28 pm
by dom
With sdcc you need to save the framepointer which in normal usage is ix. Unless you’ve marked a function with __preserve_regs nothing else needs to be saved.

The calling conventions page is valid for both compilers, the frame page needs some updating to handle 64 bit values and char passing with sdcc.

I think we’ve only come across one of the Bondwell machines that uses ix within bdos, so even failing to save ix won’t have any ill effects most of the time.

Re: __smallc __naked function with asm - which regs need to be preserved?

Posted: Mon Apr 19, 2021 12:07 am
by alank2
Thanks dom!