From: Alan Cox Date: Thu, 30 Jun 2016 12:14:56 +0000 (+0100) Subject: scc: more tidying up X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c71e4761b7b77074108b4935c805702b45f62166;p=FUZIX.git scc: more tidying up Really for 6809 it needs some work on primary() and eval() to allow for the fact the 6809 unlike the 8080/5 can actually generate useful stack relative accesses so the whole get address save address get value do stuff pop address store sequence really ought to work like a global or static but generate ,s relative addressing. Z80 might also benefit from this and use ix relative, but it's less clear, ditto 6801 especially as it has the tsx instruction. --- diff --git a/Applications/SmallC/Makefile.linux b/Applications/SmallC/Makefile.linux index b0ca5943..977c5955 100644 --- a/Applications/SmallC/Makefile.linux +++ b/Applications/SmallC/Makefile.linux @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -DTINY +CFLAGS = -DTINY -DINCDIR=\"includes/\" COPT = -O2 OBJS = initials.o data.o error.o expr.o function.o gen.o io.o \ diff --git a/Applications/SmallC/code6809.c b/Applications/SmallC/code6809.c index 4f4127eb..f6eddb49 100644 --- a/Applications/SmallC/code6809.c +++ b/Applications/SmallC/code6809.c @@ -11,6 +11,9 @@ * 360 = 3) * This compiler assumes that an integer is the SAME length as * a pointer - in fact, the compiler uses INTSIZE for both. + * + * Work this so we use d as primary and sort of use x as secondary + * (in fact we usually use ,s) */ /** @@ -150,11 +153,11 @@ int gen_get_locale(SYMBOL *sym) { newline(); return HL_REG; } else { - output_with_tab("leay "); + output_with_tab("leau "); output_number(sym->offset - stkp); output_string(",s"); newline (); - output_line("tfr y,d"); + output_line("tfr u,d"); return HL_REG; } } @@ -180,11 +183,11 @@ void gen_put_memory(SYMBOL *sym) { * @param typeobj */ void gen_put_indirect(char typeobj) { - output_line("puls d"); + output_line("puls x"); if (typeobj & CCHAR) { - output_line("stb ,y"); + output_line("stb ,x"); } else { - output_line("std ,y"); + output_line("std ,x"); } } @@ -254,9 +257,9 @@ void gen_pop(void) { * swap the primary register and the top of the stack */ void gen_swap_stack(void) { - output_line("ldy ,s"); + output_line("ldu ,s"); output_line("std ,s"); - output_line("tfr y,d"); + output_line("tfr u,d"); } /** @@ -297,6 +300,7 @@ void gen_ret(void) { * perform subroutine call to value on top of stack */ void callstk(void) { + gen_pop(); output_line ("jsr ,x"); } diff --git a/Applications/SmallC/rules.6809 b/Applications/SmallC/rules.6809 new file mode 100644 index 00000000..c9cc8491 --- /dev/null +++ b/Applications/SmallC/rules.6809 @@ -0,0 +1,63 @@ +lbra %1 +%1: += +%1: + +lbeq %1 +lbra %2 +%1: += +lbne %2 +%1: + +tfr u,d +pshs d +tfr d,u +ldd %1 += +pshs u +ldd %1 + +tfr u,d +pshs d +ldd #%1 +puls x +std ,x += +tfr u,x +ldd #%1 +std ,x + +leau %1,s +pshs u +ldd ,u +addd %2 +puls x +std ,x +subd %2 += +leax %1,s +ldd ,x +addd %2 +std ,x +subd %2 + +tfr u,d +tfr d,u +ldd ,u += +ldd ,u + +tfr u,d +tfr d,u += +tfr u,d + +leau %d,s +tfr u,x +ldd %1 +std ,x += +leax %d,s +ldd %1 +std ,x