Re: [cc65] assembler/C stack issue

From: Oliver Schmidt <ol.sc1web.de>
Date: 2011-02-11 17:54:22
Hi Gábor,

>> Assembler funcions with 8-bit return value need to zero the X register on exit.

> [...] if I have - let's say - $20 in X and in A
> too on exit, what the "C code will think", return value is $2020? It's quite
> strange, since the return value of the prototype is "char", so for unsigned
> it cannot be more than $FF. [...]

As far as I know it isn't important as long as you i.e. directly
assign the return value to an 8-bit variable. If you however use the
return value in an expression then according to the type promotion
rules all values in the expression are promoted to an 16-bit value.
The compiler makes the presumtion that the promotion of function
return values is a nop - and this presumption breaks with assembler
functions returning arbitrary values in X...

That's at least what I made up myself - we'll see how much of it is
left when Uz tells the truth ;-)

Btw: On x86 systems there is/was sort of the same problem: The
Microsoft compiler and gcc have/had different opinions on the
registers functions need to clear. I don't know by heart anymore but I
remember that I had to add an xor <reg>,<reg> in one case when porting
assembler function from one compiler to the other...

Regards,
Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Feb 11 17:54:33 2011

This archive was generated by hypermail 2.1.8 : 2011-02-11 17:54:36 CET