EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
49 stars 14 forks source link

be-code-6800.c op16_on_node() is not performing add/adc calculations correctly because the order of AccA and AccB is reversed. #130

Closed zu2 closed 1 month ago

zu2 commented 1 month ago
--- ../Fuzix-Compiler-Kit/be-code-6800.c    2024-10-24 17:13:18
+++ be-code-6800.c  2024-10-24 21:50:52
@@ -574,20 +574,20 @@
        op16_on_ptr(op, op2, off);
        break;
    case T_CONSTANT:
-       printf("\t%sa #>%u\n", op, (v + off) & 0xFFFF);
-       printf("\t%sb #<%u\n", op2, (v + off) & 0xFFFF);
+       printf("\t%sb #<%u\n", op, (v + off) & 0xFFFF);
+       printf("\t%sa #>%u\n", op2, (v + off) & 0xFFFF);
        break;
    case T_LBSTORE:
    case T_LBREF:
    case T_NSTORE:
    case T_NREF:
-       printf("\t%sa %s\n", op, addr_form(r, off, 1));
-       printf("\t%sb %s\n", op2, addr_form(r, off + 1, 1));
+       printf("\t%sb %s\n", op, addr_form(r, off + 1, 1));
+       printf("\t%sa %s\n", op2, addr_form(r, off, 1));
        break;
    case T_NAME:
    case T_LABEL:
-       printf("\t%sa %s\n", op, addr_form(r, off, 3));
-       printf("\t%sb %s\n", op2, addr_form(r, off, 1));
+       printf("\t%sb %s\n", op, addr_form(r, off, 1));
+       printf("\t%sa %s\n", op2, addr_form(r, off, 3));
        break;
    default:
        return 0;
zu2 commented 1 month ago

compile this program:

unsigned char board[16];

int main(int argc, char *argv[])
{
        unsigned char i,j;

        for (i = 0; i < 16; i++) {
                board[i] = 0;
        }
        return 0;
}

I get following code. Something is wrong with the adda/adcb part, so the array address is not calculated correctly.

        .setcpu 6800
        .code
        .export _main
        .code
_main:
        des
        des
;make local ptr off 0, rlim 254 noff 0
        tsx
        clr 1,x
        clr 0,x
;
L1_l:
;make local ptr off 0, rlim 255 noff 0
        tsx
        ldb 0,x
        clra
        pshb
        psha
        ldab #16
        jsr __cclt
;
        jeq L1_b
        jmp L1_n
L1_c:
        ldab #1
;make local ptr off 0, rlim 252 noff 0
        tsx
        jsr __xplusplusuc
;
        jmp L1_l
L1_n:
;make local ptr off 0, rlim 255 noff 0
        tsx
        ldb 0,x
        clra
        adda #>_board+0
        adcb #<_board+0
        pshb
        psha
        clrb
        tsx
        ldx ,x
        ins
        ins
        stb 0,x
;
        jmp L1_c
L1_b:
        clra
        clrb
;
L0_r:
        ins
        ins
        jmp __cleanup4
        .export _board
        .bss
_board:
        .ds 16