Calypsi-tool-chains icon indicating copy to clipboard operation
Calypsi-tool-chains copied to clipboard

Incorrect Assembly Code using >> operator and & operator

Open giovannipozzobon opened this issue 6 months ago • 3 comments

In a MEGA65 system when writing a procedure such as the following the generated assembly code does not seem correct.

void setcharsetaddr(unsigned long address)
{
POKE(VIC_BASE + 0x68, (address & 0x0000FFUL));
POKE(VIC_BASE + 0x69, (address & 0xFF00UL) >> 8);
POKE(VIC_BASE + 0x6A, (address & 0xFF0000UL) >> 16);
}
  \ 0000          setcharsetaddr:
   \ 0000 a5..                 lda     zp:_Zp
   \ 0002 8d68d0               sta     0xd068
   \ 0005 a900                 lda     #0
   \ 0007 8d69d0               sta     0xd069
   \ 000a 8d6ad0               sta     0xd06a
   \ 000d 60                   rts


By modifying the code in this way instead the generated code works correctly.

void setcharsetaddr( unsigned long addr)
{
POKE(VIC_BASE + 0x68, (addr & 0x0000FFUL));
POKE(VIC_BASE + 0x69, ((addr >> 8) & 0x0000FFUL));
POKE(VIC_BASE + 0x6A, ((addr >> 16) & 0x0000FFUL));
}

also using this it should be work fine.

void setcharsetaddr( unsigned long addr) { POKE(VIC_BASE + 0x68, addr); POKE(VIC_BASE + 0x69, (addr >> 8)); POKE(VIC_BASE + 0x6A, (addr >> 16)); }

Thanks.

giovannipozzobon avatar Aug 15 '24 06:08 giovannipozzobon