Better way to pass args from C to ASM
sgjava opened this issue · 5 comments
If you look at one of my ASM modules https://github.com/sgjava/c3l/blob/main/asm/vdcout.as you'll see the typical pop and push of the args. Is there a better way to access the stack via index maybe less expensive?
You could put the stack pointer into one of the index registers and fetch the parameters 8-bits at a time like -
LD IX,0
ADD IX,SP
LD C,(IX+2)
LD B,(IX+3)
LD E,(IX+4)
but this uses 15 bytes and is slower than the 6 bytes of push/pop instructions.
OK, makes sense. I guess that's why all the examples I've seen use pop/push.
If you look at the CSV.AS routine it loads the stack pointer into the IX register so that index register 8-bit loads can be used. If your routine calls csv it can use the same technique.
It was the late Jon Saxton who wrote the updated BIOS routine. He pushes a return address onto the stack in preparation for doing a direct BIOS call using a RET instruction and therefore he didn’t choose to use the pop/push technique to get the arguments.
So C passes everything as 16 bit args. Would this still work? Sometimes I mix uchar and ushort function arguments. It seems even it it's a little more expensive size or speed wise it might make the code cleaner.