Re: [cc65] Renaming imported zeropage variables in ca65

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-03-12 22:58:25


On Wed, Mar 12, 2003 at 10:33:51PM +0100, Marc 'BlackJack' Rintsch wrote:
> I'm using 2.9.0 and I'm feeling a bit silly because it wasn't a problem
> with renaming *within* the .proc but when I assign the variables
> *outside* of a .proc block.

This is a generic problem with scoping. With scoping, a programmer may choose
to do this:

        .importzp       foo

        .proc
                sta     foo
                foo     = $1234
        .endproc

Since assemblers must allow forward references, there an inherent problem: It
may happen that foo gets redefined inside the scope later. It's the same
problem as in the following example (which doesn't use scoping):

        lda     foo             ; Assembler assumes absolute
        foo     = $01           ; OOPS: foo is zeropage

Since having all variables loose their zero page attribute when opening a new
scope is not acceptable (old versions of ca65 did this), I had added some code
that checks if there is a variable in the enclosing scope, and if so, uses its
zeropage attribute. I've never really liked this solution, but the only better
one is to generate intermediate code and run a second pass over the
intermediate code. It seems that the workaround fails if the global symbol is
itself just a pointer to some other symbol.

I will fix this. In the mean time, you may use another workaround, which is
also ugly but helpful: Use the "global scope override operator":

        .importzp       tmp1
        tmp2          = tmp1
        .proc
                lda     ::tmp2          ; Explicitly reference the global tmp2
        .endproc

> Shouldn't both STAs use zp adressing? If I use indirect adressing like
> 'STA (foo),y' the assembler emits the expected code.

Since the latter uses an explicit zeropage addressing mode, the assembler uses
this hint to create the correct forward declaration for the variable. At the
end of the scope (or when the symbol is redefined within the scope), it is
checked and you get an error if the expected symbol does not match the actual
one. So above workaround is only needed if the assembler has a choice to make,
that influences the size of the operand.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-03-12 22:58:35 CET