EtchedPixels / CC6303

A C compiler for the 6800 series processors
Other
37 stars 7 forks source link

[bug?][right shift] Right shift operator produces broken binary #18

Closed Fabrizio-Caruso closed 2 years ago

Fabrizio-Caruso commented 2 years ago

I may have found a bug in the shift operator >> with this minimal code, which is supposed to display ABC (after pressing a key) on the MC-10. The bug is not related to the MC-10, though, as I am doing nothing special with it.

I have tested this with the very last version of CC6303 as of today 2022/03/26 (but the problem is also present in previous versions).

This minimal code crashes at a = 255>>(b-1);

#define POKE(addr,val)     (*(unsigned char*) (addr) = (val))
#include <stdio.h>
int main(void) {
        unsigned char a;
        unsigned char b;

        b = 1;
        POKE(16384,65);
        getchar();
        a = 255>>(b-1);
        POKE(16385,66);
        getchar();
        POKE(16386,67);
        return 0;
}

The problem does not exist with 255>>0 nor with 255U...

EtchedPixels commented 2 years ago

Does this fix it

diff --git a/lib6800/asr.s b/lib6800/asr.s
index 3e2ffe5..61bedd3 100644
--- a/lib6800/asr.s
+++ b/lib6800/asr.s
@@ -10,4 +10,5 @@ asraxsh:
        ror 1,x
        decb
        bne asraxsh
-       rts
+       jmp pop2get

Then rebuild the library and program

Fabrizio-Caruso commented 2 years ago

@EtchedPixels , no it does not :-( I have applied: image

Then I have rebuild CC6303, with

make clean
make
make install

and I have recompiled it with

cc68 -tmc10 ./bug.c -o bug

but it still crashes: image

Fabrizio-Caruso commented 2 years ago

Maybe the produced binary and Assembly can help you figure this out.

bug.zip

Fabrizio-Caruso commented 2 years ago

Thanks @EtchedPixels for fixing this bug! git commit a28f1be6aeffdb481708bb8aae2ddddbe8b14bb0 fixed this bug.