When I have this simple code snippet:
Code: Select all
extern unsigned char *pNumber;
#pragma zpsym("pNumber")
void __fastcall__ Test(void)
{
*pNumber = 5;
}
Code: Select all
lda _pNumber+1
sta ptr1+1
lda _pNumber
sta ptr1
lda #$05
ldy #$00
sta (ptr1),y
rts
Code: Select all
#pragma zpsym("pNumber")
--> .importzp _pNumber
Code: Select all
lda #$05
ldy #$00
sta (_pNumber),y
rts
Is there any way to get the compiler to change this behavior without adding inline Assembly manually?
I compiled with
cc65 -O Test.c
and the situation is the same in the old cc65 from cc65.org as well as the newer version from github.
By the way, if you do more than one variable access, like this:
Code: Select all
*pNumber = 5;
*pNumber = 6;
Code: Select all
lda _pNumber+1
sta ptr1+1
lda _pNumber
sta ptr1
lda #$05
ldy #$00
sta (ptr1),y
lda _pNumber+1
sta ptr1+1
lda _pNumber
sta ptr1
lda #$06
sta (ptr1),y