Monthly Archives: September 2016

6502 compiler hacking

So I’ve been working again on my port of GCC to the 6502 family of processors, and fixed a bug in a particular awkward little test case:

int N = 1;
void bar (char a[2][N]) { a[1][0] = N; }

This now compiles to:

        ; frame size 0, pretend size 0, outgoing size 0
        ldy N$
        lda N$+1
        adc _r1
        sta _r1
        sta (_r0),y

This is (a) correct, (b) not entirely obvious (because of the combination of variable-length arrays, implicit casting and so on) and (c) quite nicely efficient. That is all.