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:

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>