scc: more tidying up
authorAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 12:14:56 +0000 (13:14 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 12:14:56 +0000 (13:14 +0100)
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.

Applications/SmallC/Makefile.linux
Applications/SmallC/code6809.c
Applications/SmallC/rules.6809 [new file with mode: 0644]

index b0ca594..977c595 100644 (file)
@@ -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 \
index 4f4127e..f6eddb4 100644 (file)
@@ -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 (file)
index 0000000..c9cc849
--- /dev/null
@@ -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