Re: [cc65] Macros in inline assembler

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2012-01-19 21:16:03
Hi!

On Thu, Jan 19, 2012 at 09:03:08PM +0100, Oliver Schmidt wrote:
> Compiling the code below with -O has the line marked removed. I don't
> see the code falling into one the two categories.

This is because rand() is an external function. For C functions, the following
rules hold true:

  * fastcall functions will use A/X on entry, all others will not
  * variadic functions will use Y on entry, all others will not.
  * All register contents are assumed to get destroyed, including zero page
    "registers" with the exception of the register bank.

Since rand() is not a variadic function, the compiler regards Y as destroyed
by the function, will therefore consider the load as useless and remove it.
You can of course argue that the current implementation of rand() will not
touch Y - but this is just luck. It can change at any time. So it is actually
the code that is more than doubtful. It may stop working from one day to the
next, even if the compiler would leave the load instruction intact.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Jan 19 21:16:12 2012

This archive was generated by hypermail 2.1.8 : 2012-01-19 21:16:15 CET