diff --git a/src/dk/camelot64/kickc/icl/AsmFragment.java b/src/dk/camelot64/kickc/icl/AsmFragment.java index 1795cbe00..97a3d1f26 100644 --- a/src/dk/camelot64/kickc/icl/AsmFragment.java +++ b/src/dk/camelot64/kickc/icl/AsmFragment.java @@ -28,9 +28,15 @@ public class AsmFragment { StringBuilder signature = new StringBuilder(); if(conditionalJump.getRValue1()!=null) { signature.append(bind(conditionalJump.getRValue1())); + } + if(conditionalJump.getOperator()!=null) { signature.append(conditionalJump.getOperator().getOperator()); } - signature.append(bind(conditionalJump.getRValue2())); + if(conditionalJump.getRValue2() instanceof ConstantInteger && ((ConstantInteger) conditionalJump.getRValue2()).getNumber()==0) { + signature.append("0"); + } else { + signature.append(bind(conditionalJump.getRValue2())); + } signature.append("?"); signature.append(bind(conditionalJump.getDestination())); setSignature(signature.toString()); @@ -58,7 +64,15 @@ public class AsmFragment { if (operator != null) { signature.append(operator.getOperator()); } - signature.append(bind(rValue2)); + if( + rValue2 instanceof ConstantInteger && + ((ConstantInteger) rValue2).getNumber()==1 && + operator!=null && + (operator.getOperator().equals("-") || operator.getOperator().equals("+"))) { + signature.append("1"); + } else { + signature.append(bind(rValue2)); + } return signature.toString(); } @@ -108,6 +122,10 @@ public class AsmFragment { String name = "zpbo" + nextZpBoolIdx++; bindings.put(name, value); return name; + } else if (RegisterAllocation.RegisterType.REG_X_BYTE.equals(register.getType())) { + String name = "xby" ; + bindings.put(name, value); + return name; } else { throw new RuntimeException("Binding of register type not supported " + register.getType()); } diff --git a/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java b/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java index 513dceebe..be44c4180 100644 --- a/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java +++ b/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java @@ -22,6 +22,10 @@ public class Pass3RegisterAllocation { allocation.allocate(var, new RegisterAllocation.RegisterZpBool(currentZp++)); } } + allocation.allocate(symbols.getVariable("i#1"), RegisterAllocation.getRegisterX()); + allocation.allocate(symbols.getVariable("i#3"), RegisterAllocation.getRegisterX()); + allocation.allocate(symbols.getVariable("n1#1"), new RegisterAllocation.RegisterZpByte(8)); + allocation.allocate(symbols.getVariable("n1#2"), new RegisterAllocation.RegisterZpByte(8)); symbols.setAllocation(allocation); } diff --git a/src/dk/camelot64/kickc/icl/RegisterAllocation.java b/src/dk/camelot64/kickc/icl/RegisterAllocation.java index 6b75100ae..ba86d0143 100644 --- a/src/dk/camelot64/kickc/icl/RegisterAllocation.java +++ b/src/dk/camelot64/kickc/icl/RegisterAllocation.java @@ -36,7 +36,7 @@ public class RegisterAllocation { /** The register type. */ public enum RegisterType { - ZP_BYTE, ZP_BOOL + ZP_BYTE, ZP_BOOL, REG_X_BYTE }; /** A zero page address used as a register for a single byte variable. */ @@ -86,6 +86,23 @@ public class RegisterAllocation { } } + /** The X register. */ + public static class RegisterXByte implements Register { + @Override + public RegisterType getType() { + return RegisterType.REG_X_BYTE; + } + + @Override + public String toString() { + return "reg byte x"; + } + } + + public static Register getRegisterX() { + return new RegisterXByte(); + } + @Override public String toString() { StringBuffer out = new StringBuffer(); diff --git a/src/dk/camelot64/kickc/icl/SymbolTable.java b/src/dk/camelot64/kickc/icl/SymbolTable.java index 16a568ea6..ccd5e8105 100644 --- a/src/dk/camelot64/kickc/icl/SymbolTable.java +++ b/src/dk/camelot64/kickc/icl/SymbolTable.java @@ -1,5 +1,7 @@ package dk.camelot64.kickc.icl; +import sun.jvm.hotspot.debugger.cdbg.Sym; + import java.util.*; /** @@ -75,6 +77,10 @@ public class SymbolTable { return version; } + public Variable getVariable(String name) { + return (Variable) symbols.get(name); + } + public void setAllocation(RegisterAllocation allocation) { this.allocation = allocation; } diff --git a/src/dk/camelot64/kickc/icl/asm/xby=coby1.asm b/src/dk/camelot64/kickc/icl/asm/xby=coby1.asm new file mode 100644 index 000000000..8bc1f4465 --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/xby=coby1.asm @@ -0,0 +1 @@ +ldx #{coby1} \ No newline at end of file diff --git a/src/dk/camelot64/kickc/icl/asm/xby=xby-1.asm b/src/dk/camelot64/kickc/icl/asm/xby=xby-1.asm new file mode 100644 index 000000000..23e2d0ff8 --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/xby=xby-1.asm @@ -0,0 +1 @@ +dex \ No newline at end of file diff --git a/src/dk/camelot64/kickc/icl/asm/xby=xby.asm b/src/dk/camelot64/kickc/icl/asm/xby=xby.asm new file mode 100644 index 000000000..1ab91fbaf --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/xby=xby.asm @@ -0,0 +1 @@ +// x=x \ No newline at end of file diff --git a/src/dk/camelot64/kickc/icl/asm/xby>0?la1.asm b/src/dk/camelot64/kickc/icl/asm/xby>0?la1.asm new file mode 100644 index 000000000..0f99f0508 --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/xby>0?la1.asm @@ -0,0 +1,2 @@ +cpx #0 +bne {la1} \ No newline at end of file diff --git a/src/dk/camelot64/kickc/icl/asm/zpby1>0?la1.asm b/src/dk/camelot64/kickc/icl/asm/zpby1>0?la1.asm new file mode 100644 index 000000000..4c6ddba5c --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/zpby1>0?la1.asm @@ -0,0 +1,2 @@ +lda {zpby1} +bne {la1} diff --git a/src/dk/camelot64/kickc/icl/asm/zpby1>coby1?la1.asm b/src/dk/camelot64/kickc/icl/asm/zpby1>coby1?la1.asm new file mode 100644 index 000000000..7da7bd205 --- /dev/null +++ b/src/dk/camelot64/kickc/icl/asm/zpby1>coby1?la1.asm @@ -0,0 +1,5 @@ +lda {zpby1} +cmp #{coby1} +beq !+ +bcs {la1} +!: \ No newline at end of file diff --git a/src/dk/camelot64/kickc/test/fib.kc b/src/dk/camelot64/kickc/test/fib.kc index 0532b60a7..8e1de3fc1 100644 --- a/src/dk/camelot64/kickc/test/fib.kc +++ b/src/dk/camelot64/kickc/test/fib.kc @@ -1,10 +1,10 @@ byte n1 = 0; byte n2 = 1; -byte i = 0; +byte i = 12; byte fib = 0; -while(i<=11) { +while(i>0) { fib = n1 + n2; n1 = n2; n2 = fib; - i = i + 1; + i = i - 1; }