In the CA65 wiki, there's an article on using symbols in local scopes. In some cases, using local scope makes the assembler assume absolute mode when you really wanted zp. If you assemble the following nonsense program (no flags required just ca65 the_below_code.asm), you'll get a range error because the sta b0 instructions all assemble to absolute mode:
To correct this, it appears you can do a couple of things. One, suggested by the wiki, is to add the global scope specifier in front of the use of your symbol:
What I find odd is, I only have to do this once (such as the first time the symbol is used). Another way to correct the issue is to remove that nested .proc and just use a normal label.
What's further odd is, I remember using nested .procs for scope in the Nomolos codebase. Yet, I haven't yet found a place where CA65 is assembling to absolute mode where I'm expecting zeropage instructions.
Anyone understand this quirk of CA65 scope better than I do? Posting this will probably just make nesasm and asm6 adherants happy that they never made the switch
Code:
.globalzp b0
.proc test
lda b0
.proc nested_proc
beq label
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
.repeat 86
nop
.endrepeat
label:
rts
.endproc
.endproc
.proc test
lda b0
.proc nested_proc
beq label
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
sta b0
.repeat 86
nop
.endrepeat
label:
rts
.endproc
.endproc
To correct this, it appears you can do a couple of things. One, suggested by the wiki, is to add the global scope specifier in front of the use of your symbol:
Code:
.globalzp b0
.proc test
lda ::b0
....
.proc test
lda ::b0
....
What I find odd is, I only have to do this once (such as the first time the symbol is used). Another way to correct the issue is to remove that nested .proc and just use a normal label.
What's further odd is, I remember using nested .procs for scope in the Nomolos codebase. Yet, I haven't yet found a place where CA65 is assembling to absolute mode where I'm expecting zeropage instructions.
Anyone understand this quirk of CA65 scope better than I do? Posting this will probably just make nesasm and asm6 adherants happy that they never made the switch