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

Post Reply
alank2
Member
Posts: 52
Joined: Wed Mar 01, 2017 7:24 pm

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

Post 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?
User avatar
dom
Well known member
Posts: 1395
Joined: Sun Jul 15, 2007 10:01 pm

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

Post 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.
alank2
Member
Posts: 52
Joined: Wed Mar 01, 2017 7:24 pm

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

Post by alank2 »

Thanks dom!
Post Reply