assembly6502c64commodoreca65

CA65: 'Range error' from 16-bit computed address


Given the following CA65 code:

foo = $82

.scope
        LDA #$ff
        STA foo*$40
.endscope

I get this error message:

foo.s(5): Error: Range error (8320 not in [0..255])

Interestingly, the following version works as expected:

foo = $82

        LDA #$ff
        STA foo*$40

So how do I get this working inside a .scope?


Solution

  • If you're referring to a global symbol from inside a .scope or .proc, sometimes you have to explicitly state that the symbol is in the global scope and not the inner scope. You do this by adding the "paamayim nekudotayim" (pair of colons) operator before the symbol: ::spam. I've noticed this mostly with things like .if.

    The following compiles in ca65:

    foo = $82
    
    .scope
            LDA #$ff
            STA ::foo*$40
    .endscope