diff --git a/src/main/java/dk/camelot64/kickc/Compiler.java b/src/main/java/dk/camelot64/kickc/Compiler.java index 1be48252b..60238e4cc 100644 --- a/src/main/java/dk/camelot64/kickc/Compiler.java +++ b/src/main/java/dk/camelot64/kickc/Compiler.java @@ -38,14 +38,16 @@ public class Compiler { } public void pass6OptimizeAsm(Program program) { - CompileLog log = program.getLog(); - List pass5Optimizations = new ArrayList<>(); - pass5Optimizations.add(new Pass5NextJumpElimination(program, log)); - pass5Optimizations.add(new Pass5UnnecesaryLoadElimination(program, log)); + List pass6Optimizations = new ArrayList<>(); + pass6Optimizations.add(new Pass6NextJumpElimination(program)); + pass6Optimizations.add(new Pass6UnnecesaryLoadElimination(program)); + pass6Optimizations.add(new Pass6RedundantLabelElimination(program)); + pass6Optimizations.add(new Pass6UnusedLabelElimination(program)); boolean asmOptimized = true; + CompileLog log = program.getLog(); while (asmOptimized) { asmOptimized = false; - for (Pass5AsmOptimization optimization : pass5Optimizations) { + for (Pass6AsmOptimization optimization : pass6Optimizations) { boolean stepOptimized = optimization.optimize(); if (stepOptimized) { log.append("Succesful ASM optimization " + optimization.getClass().getSimpleName()); diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmInstruction.java b/src/main/java/dk/camelot64/kickc/asm/AsmInstruction.java index bee926da7..f50f8d19a 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmInstruction.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmInstruction.java @@ -51,4 +51,8 @@ public class AsmInstruction implements AsmLine { public void setIndex(int index) { this.index = index; } + + public void setParameter(String parameter) { + this.parameter = parameter; + } } diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmInstructionSet.java b/src/main/java/dk/camelot64/kickc/asm/AsmInstructionSet.java index 0097bc75c..d604e0568 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmInstructionSet.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmInstructionSet.java @@ -327,7 +327,7 @@ public class AsmInstructionSet { add(0xfd, "sbc", abx, 4.5); add(0xfe, "inc", abx, 7.0); add(0xff, "isc", abx, 7.0); - List jumps = Arrays.asList("jmp", "beq", "bne", "bcc", "bcs", "bvs", "bvc", "bmi", "bpl"); + List jumps = Arrays.asList("jmp", "beq", "bne", "bcc", "bcs", "bvs", "bvc", "bmi", "bpl", "jsr"); for (AsmInstructionType instruction : instructions) { if(jumps.contains(instruction.getMnemnonic())) { instruction.setJump(true); diff --git a/src/main/java/dk/camelot64/kickc/asm/AsmInstructionType.java b/src/main/java/dk/camelot64/kickc/asm/AsmInstructionType.java index 53eba7b97..ec82d32d1 100644 --- a/src/main/java/dk/camelot64/kickc/asm/AsmInstructionType.java +++ b/src/main/java/dk/camelot64/kickc/asm/AsmInstructionType.java @@ -46,7 +46,8 @@ public class AsmInstructionType { } /** - * Tells if the instruction is a jump or a branch (and the parameter is therefore a label or destination address) + * Tells if the instruction is a jump or a branch (and the parameter is therefore a label or destination address). + * * @return true if the instruction is a jump/branch */ public boolean isJump() { diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java b/src/main/java/dk/camelot64/kickc/passes/Pass6AsmOptimization.java similarity index 83% rename from src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java rename to src/main/java/dk/camelot64/kickc/passes/Pass6AsmOptimization.java index 6493fed1e..4fcd8b0f0 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5AsmOptimization.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass6AsmOptimization.java @@ -14,14 +14,12 @@ import java.util.List; * Optimization performed on Assembler Code (Asm Code). * Optimizations are performed repeatedly until none of them yield any result **/ -public abstract class Pass5AsmOptimization { +public abstract class Pass6AsmOptimization { - protected CompileLog log; private Program program; - public Pass5AsmOptimization(Program program, CompileLog log) { + public Pass6AsmOptimization(Program program) { this.program = program; - this.log = log; } /** @@ -36,7 +34,7 @@ public abstract class Pass5AsmOptimization { } public CompileLog getLog() { - return log; + return program.getLog(); } public void remove(List remove) { @@ -45,7 +43,7 @@ public abstract class Pass5AsmOptimization { for (Iterator iterator = segment.getLines().iterator(); iterator.hasNext(); ) { AsmLine line = iterator.next(); if (remove.contains(line)) { - log.append("Removing instruction " + line.getAsm()); + getLog().append("Removing instruction " + line.getAsm()); iterator.remove(); } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass6NextJumpElimination.java similarity index 81% rename from src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java rename to src/main/java/dk/camelot64/kickc/passes/Pass6NextJumpElimination.java index 69bd86366..c3d25367c 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5NextJumpElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass6NextJumpElimination.java @@ -1,6 +1,5 @@ package dk.camelot64.kickc.passes; -import dk.camelot64.kickc.CompileLog; import dk.camelot64.kickc.asm.*; import dk.camelot64.kickc.icl.Program; @@ -10,10 +9,10 @@ import java.util.List; /** * Optimize assembler code by removing jumps to labels immediately following the jump */ -public class Pass5NextJumpElimination extends Pass5AsmOptimization { +public class Pass6NextJumpElimination extends Pass6AsmOptimization { - public Pass5NextJumpElimination(Program program, CompileLog log) { - super(program, log); + public Pass6NextJumpElimination(Program program) { + super(program); } public boolean optimize() { @@ -31,7 +30,7 @@ public class Pass5NextJumpElimination extends Pass5AsmOptimization { if (line instanceof AsmInstruction) { candidate = null; AsmInstruction instruction = (AsmInstruction) line; - if (instruction.getType().isJump()) { + if (instruction.getType().isJump() && !instruction.getType().getMnemnonic().equals("jsr")) { candidate = instruction; } } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass6RedundantLabelElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass6RedundantLabelElimination.java new file mode 100644 index 000000000..629cb0632 --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/passes/Pass6RedundantLabelElimination.java @@ -0,0 +1,148 @@ +package dk.camelot64.kickc.passes; + +import dk.camelot64.kickc.asm.*; +import dk.camelot64.kickc.icl.Program; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * Optimize assembler code by removing all unused labels + */ +public class Pass6RedundantLabelElimination extends Pass6AsmOptimization { + + public Pass6RedundantLabelElimination(Program program) { + super(program); + } + + public boolean optimize() { + + List redundantLabelSet = findRedundantLabels(); + + List removeLines = new ArrayList<>(); + String currentScope = ""; + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + if(line instanceof AsmScopeBegin) { + currentScope = ((AsmScopeBegin) line).getLabel(); + } else if(line instanceof AsmScopeEnd) { + currentScope = ""; + } else if (line instanceof AsmInstruction) { + AsmInstruction instruction = (AsmInstruction) line; + if (instruction.getType().isJump()) { + String labelStr = instruction.getParameter(); + if (!labelStr.contains("!")) { + // If redundant - Replace with the shortest + for (RedundantLabels redundantLabels : redundantLabelSet) { + if (redundantLabels.getScope().equals(currentScope) && redundantLabels.isRedundant(labelStr)) { + getLog().append("Replacing label "+labelStr+" with "+redundantLabels.getKeep()); + instruction.setParameter(redundantLabels.getKeep()); + } + } + } + } + } else if(line instanceof AsmLabel) { + AsmLabel label = (AsmLabel) line; + String labelStr = label.getLabel(); + if(!labelStr.contains("!")) { + for (RedundantLabels redundantLabels : redundantLabelSet) { + if(redundantLabels.getScope().equals(currentScope) && redundantLabels.isRedundant(labelStr)) { + removeLines.add(label); + } + } + } + } + } + } + + remove(removeLines); + return removeLines.size() > 0; + } + + /** + * Find all redundant labels in the ASM + * + * @return List with all redundant labels + */ + private List findRedundantLabels() { + List redundantLabelSet = new ArrayList<>(); + RedundantLabels current = null; + String currentScope = ""; + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + boolean handled = false; + if(line instanceof AsmScopeBegin) { + currentScope = ((AsmScopeBegin) line).getLabel(); + } else if(line instanceof AsmScopeEnd) { + currentScope = ""; + } else if(line instanceof AsmLabel) { + AsmLabel label = (AsmLabel) line; + String labelStr = label.getLabel(); + if(!labelStr.contains("!")) { + if(current==null) { + current = new RedundantLabels(currentScope, labelStr); + } else { + current.add(labelStr); + } + handled = true; + } + } + if(!handled) { + if(current!=null && current.size()>1) { + redundantLabelSet.add(current); + } + current = null; + } + } + } + return redundantLabelSet; + } + + + private static class RedundantLabels { + + private String scope; + + private String keep; + + private Set redundant; + + public RedundantLabels(String scope, String label) { + this.scope = scope; + this.keep = label; + this.redundant = new LinkedHashSet<>(); + } + + public void add(String label) { + if (keep.length() < label.length()) { + redundant.add(label); + } else { + redundant.add(keep); + keep = label; + } + } + + public int size() { + return redundant.size()+1; + } + + public String getScope() { + return scope; + } + + public String getKeep() { + return keep; + } + + public boolean isRedundant(String labelStr) { + return redundant.contains(labelStr); + } + } + + + + + +} diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass6UnnecesaryLoadElimination.java similarity index 93% rename from src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java rename to src/main/java/dk/camelot64/kickc/passes/Pass6UnnecesaryLoadElimination.java index 5c6a0a004..908fc13a6 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass5UnnecesaryLoadElimination.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass6UnnecesaryLoadElimination.java @@ -1,8 +1,6 @@ package dk.camelot64.kickc.passes; -import dk.camelot64.kickc.CompileLog; import dk.camelot64.kickc.asm.*; -import dk.camelot64.kickc.asm.AsmProgramStaticRegisterValues; import dk.camelot64.kickc.icl.Program; import java.util.ArrayList; @@ -11,10 +9,10 @@ import java.util.List; /** * Maps out register values entering all instructions. Removes unnecessary loads / clears / sets */ -public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization { +public class Pass6UnnecesaryLoadElimination extends Pass6AsmOptimization { - public Pass5UnnecesaryLoadElimination(Program program, CompileLog log) { - super(program, log); + public Pass6UnnecesaryLoadElimination(Program program) { + super(program); } @Override diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass6UnusedLabelElimination.java b/src/main/java/dk/camelot64/kickc/passes/Pass6UnusedLabelElimination.java new file mode 100644 index 000000000..475130f2f --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/passes/Pass6UnusedLabelElimination.java @@ -0,0 +1,58 @@ +package dk.camelot64.kickc.passes; + +import dk.camelot64.kickc.CompileLog; +import dk.camelot64.kickc.asm.*; +import dk.camelot64.kickc.icl.Program; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * Optimize assembler code by removing all unused labels + */ +public class Pass6UnusedLabelElimination extends Pass6AsmOptimization { + + public Pass6UnusedLabelElimination(Program program) { + super(program); + } + + public boolean optimize() { + Set usedLabels = new LinkedHashSet<>(); + String currentScope = ""; + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + if(line instanceof AsmScopeBegin) { + currentScope = ((AsmScopeBegin) line).getLabel(); + } else if(line instanceof AsmScopeEnd) { + currentScope = ""; + } else if(line instanceof AsmInstruction) { + AsmInstruction instruction = (AsmInstruction) line; + if(instruction.getType().isJump()) { + String labelStr = currentScope+"::"+instruction.getParameter(); + usedLabels.add(labelStr); + } + } + } + } + List removeLines = new ArrayList<>(); + for (AsmSegment segment : getAsmProgram().getSegments()) { + for (AsmLine line : segment.getLines()) { + if(line instanceof AsmScopeBegin) { + currentScope = ((AsmScopeBegin) line).getLabel(); + } else if(line instanceof AsmScopeEnd) { + currentScope = ""; + } else if(line instanceof AsmLabel) { + AsmLabel label = (AsmLabel) line; + String labelStr = currentScope+"::"+label.getLabel(); + if(!labelStr.contains("!") && !usedLabels.contains(labelStr)) { + removeLines.add(label); + } + } + } + } + remove(removeLines); + return removeLines.size() > 0; + } +} diff --git a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.asm b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.asm index cab6ec4ab..b79f5994a 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.asm @@ -1,5 +1,3 @@ -bbegin: -b1_from_bbegin: lda #$0 sta $5 ldx #$c @@ -9,7 +7,6 @@ b1_from_bbegin: sta $2 lda #>$400 sta $2+$1 -b1_from_b3: b1: ldy #$0 lda #$51 @@ -25,12 +22,10 @@ b1: tax cpx #$27 bcs b2 -b3_from_b1: b3: lda $4 cmp #$28 - bcc b1_from_b3 -bend: + bcc b1 b2: inc $5 lda $2 @@ -44,5 +39,4 @@ b2: sec sbc #$27 tax -b3_from_b2: jmp b3 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log index ea56086f1..33a55c049 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/bresenham.log @@ -1201,7 +1201,7 @@ Re-allocated ZP register from zp byte:6 to zp byte:5 Removing instruction jmp b1 Removing instruction jmp b3 Removing instruction jmp bend -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -1285,13 +1285,16 @@ b3_from_b2: //SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp b3 -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b3 with b1 +Removing instruction b1_from_bbegin: +Removing instruction b1_from_b3: +Removing instruction b3_from_b1: +Removing instruction bend: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #$0 sta $5 @@ -1305,8 +1308,8 @@ b1_from_bbegin: sta $2 lda #>$400 sta $2+$1 + jmp b1 //SEG6 [0] phi from @3 to @1 -b1_from_b3: //SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy //SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy //SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy @@ -1333,7 +1336,6 @@ b1: cpx #$27 bcs b2 //SEG17 [6] phi from @1 to @3 -b3_from_b1: //SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy //SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy //SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy @@ -1342,9 +1344,8 @@ b3: //SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda $4 cmp #$28 - bcc b1_from_b3 + bcc b1 //SEG23 @end -bend: //SEG24 @2 b2: //SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 @@ -1369,6 +1370,164 @@ b3_from_b2: //SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy jmp b3 +Removing instruction bbegin: +Removing instruction b3_from_b2: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $5 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- xby=coby1 + ldx #$c +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $4 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $2 + lda #>$400 + sta $2+$1 + jmp b1 +//SEG6 [0] phi from @3 to @1 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy +//SEG11 @1 +b1: +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 + ldy #$0 + lda #$51 + sta ($2),y +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 + inc $4 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 + inc $2 + bne !+ + inc $2+$1 +!: +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- xby=xby_plus_coby1 + txa + clc + adc #$18 + tax +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_xby_then_la1 + cpx #$27 + bcs b2 +//SEG17 [6] phi from @1 to @3 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy +//SEG21 @3 +b3: +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 + lda $4 + cmp #$28 + bcc b1 +//SEG23 @end +//SEG24 @2 +b2: +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 + inc $5 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $2 + clc + adc #$28 + sta $2 + bcc !+ + inc $2+$1 +!: +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- xby=xby_minus_coby1 + txa + sec + sbc #$27 + tax +//SEG28 [6] phi from @2 to @3 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy + jmp b3 + +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $5 +//SEG3 [0] phi (byte) e#3 = (byte) 12 -- xby=coby1 + ldx #$c +//SEG4 [0] phi (byte) x#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $4 +//SEG5 [0] phi (byte*) cursor#3 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $2 + lda #>$400 + sta $2+$1 +//SEG6 [0] phi from @3 to @1 +//SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy +//SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy +//SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy +//SEG10 [0] phi (byte*) cursor#3 = (byte*) cursor#5 -- register_copy +//SEG11 @1 +b1: +//SEG12 [1] *((byte*) cursor#3) ← (byte) 81 [ cursor#3 x#2 e#3 y#2 ] -- _star_zpptrby1=coby1 + ldy #$0 + lda #$51 + sta ($2),y +//SEG13 [2] (byte) x#1 ← (byte) x#2 + (byte) 1 [ x#1 cursor#3 e#3 y#2 ] -- zpby1=zpby1_plus_1 + inc $4 +//SEG14 [3] (byte*) cursor#1 ← (byte*) cursor#3 + (byte) 1 [ x#1 e#3 cursor#1 y#2 ] -- zpptrby1=zpptrby1_plus_1 + inc $2 + bne !+ + inc $2+$1 +!: +//SEG15 [4] (byte) e#1 ← (byte) e#3 + (byte) 24 [ x#1 e#1 cursor#1 y#2 ] -- xby=xby_plus_coby1 + txa + clc + adc #$18 + tax +//SEG16 [5] if((byte) 39<(byte) e#1) goto @2 [ x#1 e#1 cursor#1 y#2 ] -- coby1_lt_xby_then_la1 + cpx #$27 + bcs b2 +//SEG17 [6] phi from @1 to @3 +//SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy +//SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy +//SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy +//SEG21 @3 +b3: +//SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 + lda $4 + cmp #$28 + bcc b1 +//SEG23 @end +//SEG24 @2 +b2: +//SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 + inc $5 +//SEG26 [9] (byte*) cursor#2 ← (byte*) cursor#1 + (byte) 40 [ x#1 e#1 cursor#2 y#1 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $2 + clc + adc #$28 + sta $2 + bcc !+ + inc $2+$1 +!: +//SEG27 [10] (byte) e#2 ← (byte) e#1 - (byte) 39 [ x#1 cursor#2 e#2 y#1 ] -- xby=xby_minus_coby1 + txa + sec + sbc #$27 + tax +//SEG28 [6] phi from @2 to @3 +//SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy +//SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy +//SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy + jmp b3 + FINAL SYMBOL TABLE (label) @1 (label) @2 @@ -1408,9 +1567,7 @@ zp byte:5 [ y#2 y#4 y#1 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) y#2 = (byte) 0 -- zpby1=coby1 lda #$0 sta $5 @@ -1425,7 +1582,6 @@ b1_from_bbegin: lda #>$400 sta $2+$1 //SEG6 [0] phi from @3 to @1 -b1_from_b3: //SEG7 [0] phi (byte) y#2 = (byte) y#4 -- register_copy //SEG8 [0] phi (byte) e#3 = (byte) e#5 -- register_copy //SEG9 [0] phi (byte) x#2 = (byte) x#1 -- register_copy @@ -1452,7 +1608,6 @@ b1: cpx #$27 bcs b2 //SEG17 [6] phi from @1 to @3 -b3_from_b1: //SEG18 [6] phi (byte) y#4 = (byte) y#2 -- register_copy //SEG19 [6] phi (byte) e#5 = (byte) e#1 -- register_copy //SEG20 [6] phi (byte*) cursor#5 = (byte*) cursor#1 -- register_copy @@ -1461,9 +1616,8 @@ b3: //SEG22 [7] if((byte) x#1<(byte) 40) goto @1 [ cursor#5 x#1 e#5 y#4 ] -- zpby1_lt_coby1_then_la1 lda $4 cmp #$28 - bcc b1_from_b3 + bcc b1 //SEG23 @end -bend: //SEG24 @2 b2: //SEG25 [8] (byte) y#1 ← (byte) y#2 + (byte) 1 [ x#1 e#1 cursor#1 y#1 ] -- zpby1=zpby1_plus_1 @@ -1482,7 +1636,6 @@ b2: sbc #$27 tax //SEG28 [6] phi from @2 to @3 -b3_from_b2: //SEG29 [6] phi (byte) y#4 = (byte) y#1 -- register_copy //SEG30 [6] phi (byte) e#5 = (byte) e#2 -- register_copy //SEG31 [6] phi (byte*) cursor#5 = (byte*) cursor#2 -- register_copy diff --git a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.asm b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.asm index 26a3bb87d..11c283848 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.asm @@ -1,14 +1,10 @@ -bbegin: jsr main -bend: main: { lda #$0 sta $1100 lda #$1 sta $1101 - b1_from_main: ldx #$0 - b1_from_b1: b1: lda $1100,x clc @@ -16,7 +12,6 @@ main: { sta $1102,x inx cpx #$f - bcc b1_from_b1 - breturn: + bcc b1 rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log index 6bc36638a..be47fd22b 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/fibmem.log @@ -693,7 +693,7 @@ MISSING FRAGMENTS Removing instruction jmp bend Removing instruction jmp b1 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -739,8 +739,9 @@ main: { rts } -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b1 with b1 +Removing instruction b1_from_b1: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: @@ -760,8 +761,8 @@ main: { b1_from_main: //SEG7 [3] phi (byte) main::i#2 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG8 [3] phi from main::@1 to main::@1 - b1_from_b1: //SEG9 [3] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG10 main::@1 b1: @@ -778,13 +779,99 @@ main: { inx //SEG16 [9] if((byte) main::i#1<(byte) 15) goto main::@1 [ main::i#1 ] -- xby_lt_coby1_then_la1 cpx #$f - bcc b1_from_b1 + bcc b1 //SEG17 main::@return breturn: //SEG18 [10] return [ ] rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1100 + //SEG5 [2] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 + lda #$1 + sta $1101 + //SEG6 [3] phi from main to main::@1 + //SEG7 [3] phi (byte) main::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + jmp b1 + //SEG8 [3] phi from main::@1 to main::@1 + //SEG9 [3] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG10 main::@1 + b1: + //SEG11 [4] (byte~) main::$1 ← (word) 4352 *idx (byte) main::i#2 [ main::i#2 main::$1 ] -- aby=cowo1_staridx_xby + lda $1100,x + //SEG12 [5] (byte~) main::$3 ← (word) 4353 *idx (byte) main::i#2 [ main::i#2 main::$1 main::$3 ] + // [5] main::$3 ← 4353 *idx main::i#2 // ALU + //SEG13 [6] (byte~) main::$4 ← (byte~) main::$1 + (byte~) main::$3 [ main::i#2 main::$4 ] -- aby=aby_plus_cowo1_staridx_xby + clc + adc $1101,x + //SEG14 [7] *((word) 4354 + (byte) main::i#2) ← (byte~) main::$4 [ main::i#2 ] -- cowo1_staridx_xby=aby + sta $1102,x + //SEG15 [8] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::i#1 ] -- xby=_inc_xby + inx + //SEG16 [9] if((byte) main::i#1<(byte) 15) goto main::@1 [ main::i#1 ] -- xby_lt_coby1_then_la1 + cpx #$f + bcc b1 + //SEG17 main::@return + //SEG18 [10] return [ ] + rts +} + +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1100 + //SEG5 [2] *((word) 4353) ← (byte) 1 [ ] -- _star_cowo1=coby2 + lda #$1 + sta $1101 + //SEG6 [3] phi from main to main::@1 + //SEG7 [3] phi (byte) main::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG8 [3] phi from main::@1 to main::@1 + //SEG9 [3] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG10 main::@1 + b1: + //SEG11 [4] (byte~) main::$1 ← (word) 4352 *idx (byte) main::i#2 [ main::i#2 main::$1 ] -- aby=cowo1_staridx_xby + lda $1100,x + //SEG12 [5] (byte~) main::$3 ← (word) 4353 *idx (byte) main::i#2 [ main::i#2 main::$1 main::$3 ] + // [5] main::$3 ← 4353 *idx main::i#2 // ALU + //SEG13 [6] (byte~) main::$4 ← (byte~) main::$1 + (byte~) main::$3 [ main::i#2 main::$4 ] -- aby=aby_plus_cowo1_staridx_xby + clc + adc $1101,x + //SEG14 [7] *((word) 4354 + (byte) main::i#2) ← (byte~) main::$4 [ main::i#2 ] -- cowo1_staridx_xby=aby + sta $1102,x + //SEG15 [8] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::i#1 ] -- xby=_inc_xby + inx + //SEG16 [9] if((byte) main::i#1<(byte) 15) goto main::@1 [ main::i#1 ] -- xby_lt_coby1_then_la1 + cpx #$f + bcc b1 + //SEG17 main::@return + //SEG18 [10] return [ ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -806,11 +893,9 @@ reg byte a [ main::$4 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 @@ -820,11 +905,9 @@ main: { lda #$1 sta $1101 //SEG6 [3] phi from main to main::@1 - b1_from_main: //SEG7 [3] phi (byte) main::i#2 = (byte) 0 -- xby=coby1 ldx #$0 //SEG8 [3] phi from main::@1 to main::@1 - b1_from_b1: //SEG9 [3] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG10 main::@1 b1: @@ -841,9 +924,8 @@ main: { inx //SEG16 [9] if((byte) main::i#1<(byte) 15) goto main::@1 [ main::i#1 ] -- xby_lt_coby1_then_la1 cpx #$f - bcc b1_from_b1 + bcc b1 //SEG17 main::@return - breturn: //SEG18 [10] return [ ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.asm b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.asm index adf0f6156..1e7148a42 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.asm @@ -1,38 +1,27 @@ -bbegin: jsr main -bend: main: { jsr prepare - b3_from_main: ldx #$19 jmp b3 b3_from_b11: ldx #$19 - b3_from_b3: - b3_from_b6: b3: lda $d012 cmp #$fe - bne b3_from_b3 + bne b3 b4: lda $d012 cmp #$ff bne b4 - b6: dex cpx #$0 - bne b3_from_b6 - b7: + bne b3 jsr flip - b10: jsr plot - b11: jmp b3_from_b11 - breturn: rts } plot: { - b1_from_plot: lda #$10 sta $4 lda #<$4d4 @@ -40,19 +29,15 @@ plot: { lda #>$4d4 sta $2+$1 ldx #$0 - b1_from_b3: b1: - b2_from_b1: ldy #$0 - b2_from_b2: b2: lda $1000,x sta ($2),y inx iny cpy #$10 - bcc b2_from_b2 - b3: + bcc b2 lda $2 clc adc #$28 @@ -62,22 +47,17 @@ plot: { !: dec $4 lda $4 - bne b1_from_b3 - breturn: + bne b1 rts } flip: { - b1_from_flip: lda #$10 sta $4 ldy #$f ldx #$0 - b1_from_b4: b1: - b2_from_b1: lda #$10 sta $5 - b2_from_b2: b2: lda $1000,x sta $1100,y @@ -88,34 +68,27 @@ flip: { tay dec $5 lda $5 - bne b2_from_b2 - b4: + bne b2 dey dec $4 lda $4 - bne b1_from_b4 - b3_from_b4: + bne b1 ldx #$0 - b3_from_b3: b3: lda $1100,x sta $1000,x inx cpx #$0 - bne b3_from_b3 - breturn: + bne b3 rts } prepare: { - b1_from_prepare: ldx #$0 - b1_from_b1: b1: txa sta $1000,x inx cpx #$0 - bne b1_from_b1 - breturn: + bne b1 rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log index 8c1589500..700498432 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/flipper-rex2.log @@ -4467,7 +4467,7 @@ Removing instruction jmp b3 Removing instruction jmp breturn Removing instruction jmp b1 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -4707,14 +4707,23 @@ prepare: { rts } -Removing instruction jmp b3 -Removing instruction jmp b1 -Removing instruction jmp b2 -Removing instruction jmp b1 -Removing instruction jmp b2 -Removing instruction jmp b3 -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b3_from_b6 with b3 +Replacing label b2_from_b2 with b2 +Replacing label b1_from_b3 with b1 +Replacing label b2_from_b2 with b2 +Replacing label b1_from_b4 with b1 +Replacing label b3_from_b3 with b3 +Replacing label b1_from_b1 with b1 +Removing instruction b3_from_b6: +Removing instruction b1_from_b3: +Removing instruction b2_from_b1: +Removing instruction b2_from_b2: +Removing instruction b1_from_b4: +Removing instruction b2_from_b1: +Removing instruction b2_from_b2: +Removing instruction b3_from_b3: +Removing instruction b1_from_b1: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: @@ -4738,8 +4747,8 @@ main: { jmp b3 //SEG9 [2] phi from main::@3 to main::@3 b3_from_b3: + jmp b3 //SEG10 [2] phi from main::@6 to main::@3 - b3_from_b6: //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy //SEG12 main::@3 b3: @@ -4761,7 +4770,7 @@ main: { dex //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b6 + bne b3 //SEG21 main::@7 b7: //SEG22 [9] call flip param-assignment [ ] @@ -4793,20 +4802,19 @@ plot: { sta $2+$1 //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG34 [13] phi from plot::@3 to plot::@1 - b1_from_b3: //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy //SEG38 plot::@1 b1: //SEG39 [14] phi from plot::@1 to plot::@2 - b2_from_b1: //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 ldy #$0 //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy + jmp b2 //SEG42 [14] phi from plot::@2 to plot::@2 - b2_from_b2: //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy //SEG45 plot::@2 @@ -4821,7 +4829,7 @@ plot: { iny //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 cpy #$10 - bcc b2_from_b2 + bcc b2 //SEG51 plot::@3 b3: //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 @@ -4836,7 +4844,7 @@ plot: { dec $4 //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b3 + bne b1 //SEG55 plot::@return breturn: //SEG56 [23] return [ ] @@ -4853,22 +4861,21 @@ flip: { ldy #$f //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG62 [24] phi from flip::@4 to flip::@1 - b1_from_b4: //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy //SEG66 flip::@1 b1: //SEG67 [25] phi from flip::@1 to flip::@2 - b2_from_b1: //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $5 //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy + jmp b2 //SEG71 [25] phi from flip::@2 to flip::@2 - b2_from_b2: //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy @@ -4889,7 +4896,7 @@ flip: { dec $5 //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda $5 - bne b2_from_b2 + bne b2 //SEG82 flip::@4 b4: //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby @@ -4898,13 +4905,13 @@ flip: { dec $4 //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b4 + bne b1 //SEG86 [35] phi from flip::@4 to flip::@3 b3_from_b4: //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b3 //SEG88 [35] phi from flip::@3 to flip::@3 - b3_from_b3: //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy //SEG90 flip::@3 b3: @@ -4916,7 +4923,7 @@ flip: { inx //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b3 + bne b3 //SEG95 flip::@return breturn: //SEG96 [40] return [ ] @@ -4928,8 +4935,8 @@ prepare: { b1_from_prepare: //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG100 [41] phi from prepare::@1 to prepare::@1 - b1_from_b1: //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy //SEG102 prepare::@1 b1: @@ -4940,28 +4947,41 @@ prepare: { inx //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b1_from_b1 + bne b1 //SEG106 prepare::@return breturn: //SEG107 [45] return [ ] rts } -Removing instruction jmp b3 -Succesful ASM optimization Pass5NextJumpElimination +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b3_from_main: +Removing instruction b6: +Removing instruction b7: +Removing instruction b10: +Removing instruction b11: +Removing instruction breturn: +Removing instruction b1_from_plot: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_flip: +Removing instruction b4: +Removing instruction b3_from_b4: +Removing instruction breturn: +Removing instruction b1_from_prepare: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination ASSEMBLER //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call prepare param-assignment [ ] jsr prepare //SEG5 [2] phi from main to main::@3 - b3_from_main: //SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 ldx #$19 jmp b3 @@ -4969,10 +4989,11 @@ main: { b3_from_b11: //SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 ldx #$19 + jmp b3 //SEG9 [2] phi from main::@3 to main::@3 b3_from_b3: + jmp b3 //SEG10 [2] phi from main::@6 to main::@3 - b3_from_b6: //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy //SEG12 main::@3 b3: @@ -4989,33 +5010,27 @@ main: { cmp #$ff bne b4 //SEG18 main::@6 - b6: //SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- xby=_dec_xby dex //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b6 + bne b3 //SEG21 main::@7 - b7: //SEG22 [9] call flip param-assignment [ ] jsr flip //SEG23 main::@10 - b10: //SEG24 [10] call plot param-assignment [ ] jsr plot //SEG25 main::@11 - b11: //SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp b3_from_b11 //SEG27 main::@return - breturn: //SEG28 [12] return [ ] rts } //SEG29 plot plot: { //SEG30 [13] phi from plot to plot::@1 - b1_from_plot: //SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $4 @@ -5026,20 +5041,19 @@ plot: { sta $2+$1 //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG34 [13] phi from plot::@3 to plot::@1 - b1_from_b3: //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy //SEG38 plot::@1 b1: //SEG39 [14] phi from plot::@1 to plot::@2 - b2_from_b1: //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 ldy #$0 //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy + jmp b2 //SEG42 [14] phi from plot::@2 to plot::@2 - b2_from_b2: //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy //SEG45 plot::@2 @@ -5054,9 +5068,8 @@ plot: { iny //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 cpy #$10 - bcc b2_from_b2 + bcc b2 //SEG51 plot::@3 - b3: //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda $2 clc @@ -5069,16 +5082,14 @@ plot: { dec $4 //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b3 + bne b1 //SEG55 plot::@return - breturn: //SEG56 [23] return [ ] rts } //SEG57 flip flip: { //SEG58 [24] phi from flip to flip::@1 - b1_from_flip: //SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $4 @@ -5086,22 +5097,21 @@ flip: { ldy #$f //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG62 [24] phi from flip::@4 to flip::@1 - b1_from_b4: //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy //SEG66 flip::@1 b1: //SEG67 [25] phi from flip::@1 to flip::@2 - b2_from_b1: //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $5 //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy + jmp b2 //SEG71 [25] phi from flip::@2 to flip::@2 - b2_from_b2: //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy @@ -5122,22 +5132,20 @@ flip: { dec $5 //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda $5 - bne b2_from_b2 + bne b2 //SEG82 flip::@4 - b4: //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby dey //SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec $4 //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b4 + bne b1 //SEG86 [35] phi from flip::@4 to flip::@3 - b3_from_b4: //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b3 //SEG88 [35] phi from flip::@3 to flip::@3 - b3_from_b3: //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy //SEG90 flip::@3 b3: @@ -5149,20 +5157,18 @@ flip: { inx //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b3 + bne b3 //SEG95 flip::@return - breturn: //SEG96 [40] return [ ] rts } //SEG97 prepare prepare: { //SEG98 [41] phi from prepare to prepare::@1 - b1_from_prepare: //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG100 [41] phi from prepare::@1 to prepare::@1 - b1_from_b1: //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy //SEG102 prepare::@1 b1: @@ -5173,9 +5179,636 @@ prepare: { inx //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b1_from_b1 + bne b1 + //SEG106 prepare::@return + //SEG107 [45] return [ ] + rts +} + +Removing instruction jmp b3 +Removing instruction jmp b1 +Removing instruction jmp b2 +Removing instruction jmp b1 +Removing instruction jmp b2 +Removing instruction jmp b3 +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call prepare param-assignment [ ] + jsr prepare + //SEG5 [2] phi from main to main::@3 + //SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + jmp b3 + //SEG7 [2] phi from main::@11 to main::@3 + b3_from_b11: + //SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + jmp b3 + //SEG9 [2] phi from main::@3 to main::@3 + b3_from_b3: + //SEG10 [2] phi from main::@6 to main::@3 + //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy + //SEG12 main::@3 + b3: + //SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$fe + bne b3_from_b3 + //SEG15 main::@4 + b4: + //SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$ff + bne b4 + //SEG18 main::@6 + //SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- xby=_dec_xby + dex + //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG21 main::@7 + //SEG22 [9] call flip param-assignment [ ] + jsr flip + //SEG23 main::@10 + //SEG24 [10] call plot param-assignment [ ] + jsr plot + //SEG25 main::@11 + //SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 + jmp b3_from_b11 + //SEG27 main::@return + //SEG28 [12] return [ ] + rts +} +//SEG29 plot +plot: { + //SEG30 [13] phi from plot to plot::@1 + //SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 + lda #<$4d4 + sta $2 + lda #>$4d4 + sta $2+$1 + //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG34 [13] phi from plot::@3 to plot::@1 + //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy + //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy + //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy + //SEG38 plot::@1 + b1: + //SEG39 [14] phi from plot::@1 to plot::@2 + //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy + //SEG42 [14] phi from plot::@2 to plot::@2 + //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy + //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy + //SEG45 plot::@2 + b2: + //SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_yby=aby + sta ($2),y + //SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- xby=_inc_xby + inx + //SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby=_inc_yby + iny + //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 + cpy #$10 + bcc b2 + //SEG51 plot::@3 + //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $2 + clc + adc #$28 + sta $2 + bcc !+ + inc $2+$1 + !: + //SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG55 plot::@return + //SEG56 [23] return [ ] + rts +} +//SEG57 flip +flip: { + //SEG58 [24] phi from flip to flip::@1 + //SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- yby=coby1 + ldy #$f + //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG62 [24] phi from flip::@4 to flip::@1 + //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy + //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy + //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy + //SEG66 flip::@1 + b1: + //SEG67 [25] phi from flip::@1 to flip::@2 + //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $5 + //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy + //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy + //SEG71 [25] phi from flip::@2 to flip::@2 + //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy + //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy + //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy + //SEG75 flip::@2 + b2: + //SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_yby=aby + sta $1100,y + //SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- xby=_inc_xby + inx + //SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- yby=yby_plus_coby1 + tya + clc + adc #$10 + tay + //SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 + dec $5 + //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 + lda $5 + bne b2 + //SEG82 flip::@4 + //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby + dey + //SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG86 [35] phi from flip::@4 to flip::@3 + //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG88 [35] phi from flip::@3 to flip::@3 + //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy + //SEG90 flip::@3 + b3: + //SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- aby=cowo1_staridx_xby + lda $1100,x + //SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_xby=aby + sta $1000,x + //SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- xby=_inc_xby + inx + //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG95 flip::@return + //SEG96 [40] return [ ] + rts +} +//SEG97 prepare +prepare: { + //SEG98 [41] phi from prepare to prepare::@1 + //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG100 [41] phi from prepare::@1 to prepare::@1 + //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy + //SEG102 prepare::@1 + b1: + //SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_xby=xby + txa + sta $1000,x + //SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- xby=_inc_xby + inx + //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b1 + //SEG106 prepare::@return + //SEG107 [45] return [ ] + rts +} + +Replacing label b3_from_b3 with b3 +Removing instruction b3_from_b3: +Succesful ASM optimization Pass6RedundantLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call prepare param-assignment [ ] + jsr prepare + //SEG5 [2] phi from main to main::@3 + //SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + jmp b3 + //SEG7 [2] phi from main::@11 to main::@3 + b3_from_b11: + //SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + jmp b3 + //SEG9 [2] phi from main::@3 to main::@3 + //SEG10 [2] phi from main::@6 to main::@3 + //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy + //SEG12 main::@3 + b3: + //SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$fe + bne b3 + //SEG15 main::@4 + b4: + //SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$ff + bne b4 + //SEG18 main::@6 + //SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- xby=_dec_xby + dex + //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG21 main::@7 + //SEG22 [9] call flip param-assignment [ ] + jsr flip + //SEG23 main::@10 + //SEG24 [10] call plot param-assignment [ ] + jsr plot + //SEG25 main::@11 + //SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 + jmp b3_from_b11 + //SEG27 main::@return + //SEG28 [12] return [ ] + rts +} +//SEG29 plot +plot: { + //SEG30 [13] phi from plot to plot::@1 + //SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 + lda #<$4d4 + sta $2 + lda #>$4d4 + sta $2+$1 + //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG34 [13] phi from plot::@3 to plot::@1 + //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy + //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy + //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy + //SEG38 plot::@1 + b1: + //SEG39 [14] phi from plot::@1 to plot::@2 + //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy + //SEG42 [14] phi from plot::@2 to plot::@2 + //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy + //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy + //SEG45 plot::@2 + b2: + //SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_yby=aby + sta ($2),y + //SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- xby=_inc_xby + inx + //SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby=_inc_yby + iny + //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 + cpy #$10 + bcc b2 + //SEG51 plot::@3 + //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $2 + clc + adc #$28 + sta $2 + bcc !+ + inc $2+$1 + !: + //SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG55 plot::@return + //SEG56 [23] return [ ] + rts +} +//SEG57 flip +flip: { + //SEG58 [24] phi from flip to flip::@1 + //SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- yby=coby1 + ldy #$f + //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG62 [24] phi from flip::@4 to flip::@1 + //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy + //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy + //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy + //SEG66 flip::@1 + b1: + //SEG67 [25] phi from flip::@1 to flip::@2 + //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $5 + //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy + //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy + //SEG71 [25] phi from flip::@2 to flip::@2 + //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy + //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy + //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy + //SEG75 flip::@2 + b2: + //SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_yby=aby + sta $1100,y + //SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- xby=_inc_xby + inx + //SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- yby=yby_plus_coby1 + tya + clc + adc #$10 + tay + //SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 + dec $5 + //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 + lda $5 + bne b2 + //SEG82 flip::@4 + //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby + dey + //SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG86 [35] phi from flip::@4 to flip::@3 + //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG88 [35] phi from flip::@3 to flip::@3 + //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy + //SEG90 flip::@3 + b3: + //SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- aby=cowo1_staridx_xby + lda $1100,x + //SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_xby=aby + sta $1000,x + //SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- xby=_inc_xby + inx + //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG95 flip::@return + //SEG96 [40] return [ ] + rts +} +//SEG97 prepare +prepare: { + //SEG98 [41] phi from prepare to prepare::@1 + //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG100 [41] phi from prepare::@1 to prepare::@1 + //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy + //SEG102 prepare::@1 + b1: + //SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_xby=xby + txa + sta $1000,x + //SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- xby=_inc_xby + inx + //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b1 + //SEG106 prepare::@return + //SEG107 [45] return [ ] + rts +} + +Removing instruction jmp b3 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call prepare param-assignment [ ] + jsr prepare + //SEG5 [2] phi from main to main::@3 + //SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + jmp b3 + //SEG7 [2] phi from main::@11 to main::@3 + b3_from_b11: + //SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 + ldx #$19 + //SEG9 [2] phi from main::@3 to main::@3 + //SEG10 [2] phi from main::@6 to main::@3 + //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy + //SEG12 main::@3 + b3: + //SEG13 [3] (byte~) main::$1 ← * (word) 53266 [ main::$1 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$fe + bne b3 + //SEG15 main::@4 + b4: + //SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- aby=_star_cowo1 + lda $d012 + //SEG17 [6] if((byte~) main::$3!=(byte) 255) goto main::@4 [ main::c#2 ] -- aby_neq_coby1_then_la1 + cmp #$ff + bne b4 + //SEG18 main::@6 + //SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- xby=_dec_xby + dex + //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG21 main::@7 + //SEG22 [9] call flip param-assignment [ ] + jsr flip + //SEG23 main::@10 + //SEG24 [10] call plot param-assignment [ ] + jsr plot + //SEG25 main::@11 + //SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 + jmp b3_from_b11 + //SEG27 main::@return + //SEG28 [12] return [ ] + rts +} +//SEG29 plot +plot: { + //SEG30 [13] phi from plot to plot::@1 + //SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG32 [13] phi (byte*) plot::line#2 = (word) 1236 -- zpptrby1=cowo1 + lda #<$4d4 + sta $2 + lda #>$4d4 + sta $2+$1 + //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG34 [13] phi from plot::@3 to plot::@1 + //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy + //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy + //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy + //SEG38 plot::@1 + b1: + //SEG39 [14] phi from plot::@1 to plot::@2 + //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy + //SEG42 [14] phi from plot::@2 to plot::@2 + //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy + //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy + //SEG45 plot::@2 + b2: + //SEG46 [15] (byte~) plot::$3 ← (word) 4096 *idx (byte) plot::i#2 [ plot::i#2 plot::line#2 plot::x#2 plot::$3 plot::y#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG47 [16] *((byte*) plot::line#2 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::i#2 plot::line#2 plot::x#2 plot::y#2 ] -- zpptrby1_staridx_yby=aby + sta ($2),y + //SEG48 [17] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::i#1 plot::line#2 plot::x#2 plot::y#2 ] -- xby=_inc_xby + inx + //SEG49 [18] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby=_inc_yby + iny + //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 + cpy #$10 + bcc b2 + //SEG51 plot::@3 + //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $2 + clc + adc #$28 + sta $2 + bcc !+ + inc $2+$1 + !: + //SEG53 [21] (byte) plot::y#1 ← -- (byte) plot::y#2 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG55 plot::@return + //SEG56 [23] return [ ] + rts +} +//SEG57 flip +flip: { + //SEG58 [24] phi from flip to flip::@1 + //SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $4 + //SEG60 [24] phi (byte) flip::dstIdx#5 = (byte) 15 -- yby=coby1 + ldy #$f + //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG62 [24] phi from flip::@4 to flip::@1 + //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy + //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy + //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy + //SEG66 flip::@1 + b1: + //SEG67 [25] phi from flip::@1 to flip::@2 + //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 + lda #$10 + sta $5 + //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy + //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy + //SEG71 [25] phi from flip::@2 to flip::@2 + //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy + //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy + //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy + //SEG75 flip::@2 + b2: + //SEG76 [26] (byte~) flip::$0 ← (word) 4096 *idx (byte) flip::srcIdx#2 [ flip::srcIdx#2 flip::dstIdx#3 flip::$0 flip::c#2 flip::r#2 ] -- aby=cowo1_staridx_xby + lda $1000,x + //SEG77 [27] *((word) 4352 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- cowo1_staridx_yby=aby + sta $1100,y + //SEG78 [28] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::srcIdx#1 flip::dstIdx#3 flip::c#2 flip::r#2 ] -- xby=_inc_xby + inx + //SEG79 [29] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte) 16 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#2 flip::r#2 ] -- yby=yby_plus_coby1 + tya + clc + adc #$10 + tay + //SEG80 [30] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1=_dec_zpby1 + dec $5 + //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 + lda $5 + bne b2 + //SEG82 flip::@4 + //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby + dey + //SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 + lda $4 + bne b1 + //SEG86 [35] phi from flip::@4 to flip::@3 + //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG88 [35] phi from flip::@3 to flip::@3 + //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy + //SEG90 flip::@3 + b3: + //SEG91 [36] (byte~) flip::$4 ← (word) 4352 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] -- aby=cowo1_staridx_xby + lda $1100,x + //SEG92 [37] *((word) 4096 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] -- cowo1_staridx_xby=aby + sta $1000,x + //SEG93 [38] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] -- xby=_inc_xby + inx + //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b3 + //SEG95 flip::@return + //SEG96 [40] return [ ] + rts +} +//SEG97 prepare +prepare: { + //SEG98 [41] phi from prepare to prepare::@1 + //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG100 [41] phi from prepare::@1 to prepare::@1 + //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy + //SEG102 prepare::@1 + b1: + //SEG103 [42] *((word) 4096 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] -- cowo1_staridx_xby=xby + txa + sta $1000,x + //SEG104 [43] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] -- xby=_inc_xby + inx + //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 + cpx #$0 + bne b1 //SEG106 prepare::@return - breturn: //SEG107 [45] return [ ] rts } @@ -5270,17 +5903,14 @@ reg byte a [ flip::$4 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call prepare param-assignment [ ] jsr prepare //SEG5 [2] phi from main to main::@3 - b3_from_main: //SEG6 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 ldx #$19 jmp b3 @@ -5289,9 +5919,7 @@ main: { //SEG8 [2] phi (byte) main::c#2 = (byte) 25 -- xby=coby1 ldx #$19 //SEG9 [2] phi from main::@3 to main::@3 - b3_from_b3: //SEG10 [2] phi from main::@6 to main::@3 - b3_from_b6: //SEG11 [2] phi (byte) main::c#2 = (byte) main::c#1 -- register_copy //SEG12 main::@3 b3: @@ -5299,7 +5927,7 @@ main: { lda $d012 //SEG14 [4] if((byte~) main::$1!=(byte) 254) goto main::@3 [ main::c#2 ] -- aby_neq_coby1_then_la1 cmp #$fe - bne b3_from_b3 + bne b3 //SEG15 main::@4 b4: //SEG16 [5] (byte~) main::$3 ← * (word) 53266 [ main::$3 main::c#2 ] -- aby=_star_cowo1 @@ -5308,33 +5936,27 @@ main: { cmp #$ff bne b4 //SEG18 main::@6 - b6: //SEG19 [7] (byte) main::c#1 ← -- (byte) main::c#2 [ main::c#1 ] -- xby=_dec_xby dex //SEG20 [8] if((byte) main::c#1!=(byte) 0) goto main::@3 [ main::c#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b6 + bne b3 //SEG21 main::@7 - b7: //SEG22 [9] call flip param-assignment [ ] jsr flip //SEG23 main::@10 - b10: //SEG24 [10] call plot param-assignment [ ] jsr plot //SEG25 main::@11 - b11: //SEG26 [11] if(true) goto main::@3 [ ] -- true_then_la1 jmp b3_from_b11 //SEG27 main::@return - breturn: //SEG28 [12] return [ ] rts } //SEG29 plot plot: { //SEG30 [13] phi from plot to plot::@1 - b1_from_plot: //SEG31 [13] phi (byte) plot::y#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $4 @@ -5346,19 +5968,16 @@ plot: { //SEG33 [13] phi (byte) plot::i#3 = (byte) 0 -- xby=coby1 ldx #$0 //SEG34 [13] phi from plot::@3 to plot::@1 - b1_from_b3: //SEG35 [13] phi (byte) plot::y#2 = (byte) plot::y#1 -- register_copy //SEG36 [13] phi (byte*) plot::line#2 = (byte*) plot::line#1 -- register_copy //SEG37 [13] phi (byte) plot::i#3 = (byte) plot::i#1 -- register_copy //SEG38 plot::@1 b1: //SEG39 [14] phi from plot::@1 to plot::@2 - b2_from_b1: //SEG40 [14] phi (byte) plot::x#2 = (byte) 0 -- yby=coby1 ldy #$0 //SEG41 [14] phi (byte) plot::i#2 = (byte) plot::i#3 -- register_copy //SEG42 [14] phi from plot::@2 to plot::@2 - b2_from_b2: //SEG43 [14] phi (byte) plot::x#2 = (byte) plot::x#1 -- register_copy //SEG44 [14] phi (byte) plot::i#2 = (byte) plot::i#1 -- register_copy //SEG45 plot::@2 @@ -5373,9 +5992,8 @@ plot: { iny //SEG50 [19] if((byte) plot::x#1<(byte) 16) goto plot::@2 [ plot::i#1 plot::x#1 plot::line#2 plot::y#2 ] -- yby_lt_coby1_then_la1 cpy #$10 - bcc b2_from_b2 + bcc b2 //SEG51 plot::@3 - b3: //SEG52 [20] (byte*) plot::line#1 ← (byte*) plot::line#2 + (byte) 40 [ plot::i#1 plot::line#1 plot::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda $2 clc @@ -5388,16 +6006,14 @@ plot: { dec $4 //SEG54 [22] if((byte) plot::y#1!=(byte) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b3 + bne b1 //SEG55 plot::@return - breturn: //SEG56 [23] return [ ] rts } //SEG57 flip flip: { //SEG58 [24] phi from flip to flip::@1 - b1_from_flip: //SEG59 [24] phi (byte) flip::r#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $4 @@ -5406,21 +6022,18 @@ flip: { //SEG61 [24] phi (byte) flip::srcIdx#3 = (byte) 0 -- xby=coby1 ldx #$0 //SEG62 [24] phi from flip::@4 to flip::@1 - b1_from_b4: //SEG63 [24] phi (byte) flip::r#2 = (byte) flip::r#1 -- register_copy //SEG64 [24] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 -- register_copy //SEG65 [24] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 -- register_copy //SEG66 flip::@1 b1: //SEG67 [25] phi from flip::@1 to flip::@2 - b2_from_b1: //SEG68 [25] phi (byte) flip::c#2 = (byte) 16 -- zpby1=coby1 lda #$10 sta $5 //SEG69 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 -- register_copy //SEG70 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 -- register_copy //SEG71 [25] phi from flip::@2 to flip::@2 - b2_from_b2: //SEG72 [25] phi (byte) flip::c#2 = (byte) flip::c#1 -- register_copy //SEG73 [25] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 -- register_copy //SEG74 [25] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 -- register_copy @@ -5441,22 +6054,19 @@ flip: { dec $5 //SEG81 [31] if((byte) flip::c#1!=(byte) 0) goto flip::@2 [ flip::srcIdx#1 flip::dstIdx#1 flip::c#1 flip::r#2 ] -- zpby1_neq_0_then_la1 lda $5 - bne b2_from_b2 + bne b2 //SEG82 flip::@4 - b4: //SEG83 [32] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#2 ] -- yby=_dec_yby dey //SEG84 [33] (byte) flip::r#1 ← -- (byte) flip::r#2 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1=_dec_zpby1 dec $4 //SEG85 [34] if((byte) flip::r#1!=(byte) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] -- zpby1_neq_0_then_la1 lda $4 - bne b1_from_b4 + bne b1 //SEG86 [35] phi from flip::@4 to flip::@3 - b3_from_b4: //SEG87 [35] phi (byte) flip::i#2 = (byte) 0 -- xby=coby1 ldx #$0 //SEG88 [35] phi from flip::@3 to flip::@3 - b3_from_b3: //SEG89 [35] phi (byte) flip::i#2 = (byte) flip::i#1 -- register_copy //SEG90 flip::@3 b3: @@ -5468,20 +6078,17 @@ flip: { inx //SEG94 [39] if((byte) flip::i#1!=(byte) 0) goto flip::@3 [ flip::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b3_from_b3 + bne b3 //SEG95 flip::@return - breturn: //SEG96 [40] return [ ] rts } //SEG97 prepare prepare: { //SEG98 [41] phi from prepare to prepare::@1 - b1_from_prepare: //SEG99 [41] phi (byte) prepare::i#2 = (byte) 0 -- xby=coby1 ldx #$0 //SEG100 [41] phi from prepare::@1 to prepare::@1 - b1_from_b1: //SEG101 [41] phi (byte) prepare::i#2 = (byte) prepare::i#1 -- register_copy //SEG102 prepare::@1 b1: @@ -5492,9 +6099,8 @@ prepare: { inx //SEG105 [44] if((byte) prepare::i#1!=(byte) 0) goto prepare::@1 [ prepare::i#1 ] -- xby_neq_0_then_la1 cpx #$0 - bne b1_from_b1 + bne b1 //SEG106 prepare::@return - breturn: //SEG107 [45] return [ ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.asm b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.asm index 8f0d5455c..0752bf4cd 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.asm @@ -1,22 +1,16 @@ -bbegin: -b1_from_bbegin: lda #$0 ldx #$a -b1_from_b3: b1: cpx #$5 beq !+ bcs b2 !: -b3_from_b1: b3: dex cpx #$0 - bne b1_from_b3 -bend: + bne b1 b2: stx $ff clc adc $ff -b3_from_b2: jmp b3 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log index c373c71f8..8aa462366 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopmin.log @@ -442,7 +442,7 @@ Uplifting [] best 405 combination reg byte a [ s#2 s#4 s#1 ] reg byte x [ i#2 i# Removing instruction jmp b1 Removing instruction jmp b3 Removing instruction jmp bend -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -487,19 +487,22 @@ b3_from_b2: //SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp b3 -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b3 with b1 +Removing instruction b1_from_bbegin: +Removing instruction b1_from_b3: +Removing instruction b3_from_b1: +Removing instruction bend: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) s#2 = (byte) 0 -- aby=coby1 lda #$0 //SEG3 [0] phi (byte) i#2 = (byte) 10 -- xby=coby1 ldx #$a + jmp b1 //SEG4 [0] phi from @3 to @1 -b1_from_b3: //SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy //SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy //SEG7 @1 @@ -510,7 +513,6 @@ b1: bcs b2 !: //SEG9 [2] phi from @1 to @3 -b3_from_b1: //SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy //SEG11 @3 b3: @@ -518,9 +520,8 @@ b3: dex //SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b3 + bne b1 //SEG14 @end -bend: //SEG15 @2 b2: //SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- aby=aby_plus_xby @@ -532,6 +533,86 @@ b3_from_b2: //SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp b3 +Removing instruction bbegin: +Removing instruction b3_from_b2: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- aby=coby1 + lda #$0 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- xby=coby1 + ldx #$a + jmp b1 +//SEG4 [0] phi from @3 to @1 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 +b1: +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- xby_gt_coby1_then_la1 + cpx #$5 + beq !+ + bcs b2 +!: +//SEG9 [2] phi from @1 to @3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy +//SEG11 @3 +b3: +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- xby=_dec_xby + dex +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 +//SEG14 @end +//SEG15 @2 +b2: +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- aby=aby_plus_xby + stx $ff + clc + adc $ff +//SEG17 [2] phi from @2 to @3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy + jmp b3 + +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) s#2 = (byte) 0 -- aby=coby1 + lda #$0 +//SEG3 [0] phi (byte) i#2 = (byte) 10 -- xby=coby1 + ldx #$a +//SEG4 [0] phi from @3 to @1 +//SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy +//SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG7 @1 +b1: +//SEG8 [1] if((byte) i#2>(byte) 5) goto @2 [ i#2 s#2 ] -- xby_gt_coby1_then_la1 + cpx #$5 + beq !+ + bcs b2 +!: +//SEG9 [2] phi from @1 to @3 +//SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy +//SEG11 @3 +b3: +//SEG12 [3] (byte) i#1 ← -- (byte) i#2 [ i#1 s#4 ] -- xby=_dec_xby + dex +//SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 +//SEG14 @end +//SEG15 @2 +b2: +//SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- aby=aby_plus_xby + stx $ff + clc + adc $ff +//SEG17 [2] phi from @2 to @3 +//SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy + jmp b3 + FINAL SYMBOL TABLE (label) @1 (label) @2 @@ -551,15 +632,12 @@ reg byte a [ s#2 s#4 s#1 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) s#2 = (byte) 0 -- aby=coby1 lda #$0 //SEG3 [0] phi (byte) i#2 = (byte) 10 -- xby=coby1 ldx #$a //SEG4 [0] phi from @3 to @1 -b1_from_b3: //SEG5 [0] phi (byte) s#2 = (byte) s#4 -- register_copy //SEG6 [0] phi (byte) i#2 = (byte) i#1 -- register_copy //SEG7 @1 @@ -570,7 +648,6 @@ b1: bcs b2 !: //SEG9 [2] phi from @1 to @3 -b3_from_b1: //SEG10 [2] phi (byte) s#4 = (byte) s#2 -- register_copy //SEG11 @3 b3: @@ -578,9 +655,8 @@ b3: dex //SEG13 [4] if((byte) i#1>(byte) 0) goto @1 [ i#1 s#4 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b3 + bne b1 //SEG14 @end -bend: //SEG15 @2 b2: //SEG16 [5] (byte) s#1 ← (byte) s#2 + (byte) i#2 [ i#2 s#1 ] -- aby=aby_plus_xby @@ -588,7 +664,6 @@ b2: clc adc $ff //SEG17 [2] phi from @2 to @3 -b3_from_b2: //SEG18 [2] phi (byte) s#4 = (byte) s#1 -- register_copy jmp b3 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.asm b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.asm index 2511a4484..34712a466 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.asm @@ -1,28 +1,19 @@ -bbegin: jsr main -bend: main: { - b1_from_main: ldy #$64 - b1_from_b3: b1: jsr nest - b3: dey cpy #$0 - bne b1_from_b3 - breturn: + bne b1 rts } nest: { - b1_from_nest: ldx #$64 - b1_from_b1: b1: stx $400 dex cpx #$0 - bne b1_from_b1 - breturn: + bne b1 rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log index 027235b53..244fa35a4 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest.log @@ -820,7 +820,7 @@ Removing instruction jmp b3 Removing instruction jmp breturn Removing instruction jmp b1 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -879,9 +879,11 @@ nest: { rts } -Removing instruction jmp b1 -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b3 with b1 +Replacing label b1_from_b1 with b1 +Removing instruction b1_from_b3: +Removing instruction b1_from_b1: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: @@ -895,8 +897,8 @@ main: { b1_from_main: //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- yby=coby1 ldy #$64 + jmp b1 //SEG6 [1] phi from main::@3 to main::@1 - b1_from_b3: //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG8 main::@1 b1: @@ -908,7 +910,7 @@ main: { dey //SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- yby_gt_0_then_la1 cpy #$0 - bne b1_from_b3 + bne b1 //SEG13 main::@return breturn: //SEG14 [5] return [ ] @@ -920,8 +922,8 @@ nest: { b1_from_nest: //SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- xby=coby1 ldx #$64 + jmp b1 //SEG18 [6] phi from nest::@1 to nest::@1 - b1_from_b1: //SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy //SEG20 nest::@1 b1: @@ -931,13 +933,120 @@ nest: { dex //SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b1 + bne b1 //SEG24 nest::@return breturn: //SEG25 [10] return [ main::i#2 ] rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_nest: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- yby=coby1 + ldy #$64 + jmp b1 + //SEG6 [1] phi from main::@3 to main::@1 + //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG8 main::@1 + b1: + //SEG9 [2] call nest param-assignment [ main::i#2 ] + jsr nest + //SEG10 main::@3 + //SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- yby=_dec_yby + dey + //SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- yby_gt_0_then_la1 + cpy #$0 + bne b1 + //SEG13 main::@return + //SEG14 [5] return [ ] + rts +} +//SEG15 nest +nest: { + //SEG16 [6] phi from nest to nest::@1 + //SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- xby=coby1 + ldx #$64 + jmp b1 + //SEG18 [6] phi from nest::@1 to nest::@1 + //SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy + //SEG20 nest::@1 + b1: + //SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=xby + stx $400 + //SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- xby=_dec_xby + dex + //SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 + //SEG24 nest::@return + //SEG25 [10] return [ main::i#2 ] + rts +} + +Removing instruction jmp b1 +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- yby=coby1 + ldy #$64 + //SEG6 [1] phi from main::@3 to main::@1 + //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG8 main::@1 + b1: + //SEG9 [2] call nest param-assignment [ main::i#2 ] + jsr nest + //SEG10 main::@3 + //SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- yby=_dec_yby + dey + //SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- yby_gt_0_then_la1 + cpy #$0 + bne b1 + //SEG13 main::@return + //SEG14 [5] return [ ] + rts +} +//SEG15 nest +nest: { + //SEG16 [6] phi from nest to nest::@1 + //SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- xby=coby1 + ldx #$64 + //SEG18 [6] phi from nest::@1 to nest::@1 + //SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy + //SEG20 nest::@1 + b1: + //SEG21 [7] *((word) 1024) ← (byte) nest::j#2 [ main::i#2 nest::j#2 ] -- _star_cowo1=xby + stx $400 + //SEG22 [8] (byte) nest::j#1 ← -- (byte) nest::j#2 [ main::i#2 nest::j#1 ] -- xby=_dec_xby + dex + //SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 + //SEG24 nest::@return + //SEG25 [10] return [ main::i#2 ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -961,44 +1070,36 @@ reg byte x [ nest::j#2 nest::j#1 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] phi from main to main::@1 - b1_from_main: //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- yby=coby1 ldy #$64 //SEG6 [1] phi from main::@3 to main::@1 - b1_from_b3: //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG8 main::@1 b1: //SEG9 [2] call nest param-assignment [ main::i#2 ] jsr nest //SEG10 main::@3 - b3: //SEG11 [3] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- yby=_dec_yby dey //SEG12 [4] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- yby_gt_0_then_la1 cpy #$0 - bne b1_from_b3 + bne b1 //SEG13 main::@return - breturn: //SEG14 [5] return [ ] rts } //SEG15 nest nest: { //SEG16 [6] phi from nest to nest::@1 - b1_from_nest: //SEG17 [6] phi (byte) nest::j#2 = (byte) 100 -- xby=coby1 ldx #$64 //SEG18 [6] phi from nest::@1 to nest::@1 - b1_from_b1: //SEG19 [6] phi (byte) nest::j#2 = (byte) nest::j#1 -- register_copy //SEG20 nest::@1 b1: @@ -1008,9 +1109,8 @@ nest: { dex //SEG23 [9] if((byte) nest::j#1>(byte) 0) goto nest::@1 [ main::i#2 nest::j#1 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b1 + bne b1 //SEG24 nest::@return - breturn: //SEG25 [10] return [ main::i#2 ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.asm b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.asm index fd19bef35..b849053f0 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.asm @@ -1,69 +1,47 @@ -bbegin: jsr main -bend: main: { - b1_from_main: lda #$64 sta $2 - b1_from_b3: b1: - b2_from_b1: lda #$64 sta $3 - b2_from_b5: b2: jsr nest1 - b5: dec $3 lda $3 - bne b2_from_b5 - b3: + bne b2 dec $2 lda $2 - bne b1_from_b3 - breturn: + bne b1 rts } nest1: { - b1_from_nest1: lda #$64 sta $4 - b1_from_b3: b1: - b2_from_b1: lda #$64 - b2_from_b5: b2: jsr nest2 - b5: sec sbc #$1 cmp #$0 - bne b2_from_b5 - b3: + bne b2 dec $4 lda $4 - bne b1_from_b3 - breturn: + bne b1 rts } nest2: { - b1_from_nest2: ldx #$64 - b1_from_b3: b1: - b2_from_b1: ldy #$64 - b2_from_b2: b2: sty $400 dey cpy #$0 - bne b2_from_b2 - b3: + bne b2 dex cpx #$0 - bne b1_from_b3 - breturn: + bne b1 rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log index 243dadacb..56f52fa59 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopnest2.log @@ -2118,7 +2118,7 @@ Removing instruction jmp b1 Removing instruction jmp b2 Removing instruction jmp b3 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -2258,13 +2258,22 @@ nest2: { rts } -Removing instruction jmp b1 -Removing instruction jmp b2 -Removing instruction jmp b1 -Removing instruction jmp b2 -Removing instruction jmp b1 -Removing instruction jmp b2 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b2_from_b5 with b2 +Replacing label b1_from_b3 with b1 +Replacing label b2_from_b5 with b2 +Replacing label b1_from_b3 with b1 +Replacing label b2_from_b2 with b2 +Replacing label b1_from_b3 with b1 +Removing instruction b1_from_b3: +Removing instruction b2_from_b1: +Removing instruction b2_from_b5: +Removing instruction b1_from_b3: +Removing instruction b2_from_b1: +Removing instruction b2_from_b5: +Removing instruction b1_from_b3: +Removing instruction b2_from_b1: +Removing instruction b2_from_b2: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: @@ -2279,18 +2288,17 @@ main: { //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $2 + jmp b1 //SEG6 [1] phi from main::@3 to main::@1 - b1_from_b3: //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG8 main::@1 b1: //SEG9 [2] phi from main::@1 to main::@2 - b2_from_b1: //SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $3 + jmp b2 //SEG11 [2] phi from main::@5 to main::@2 - b2_from_b5: //SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy //SEG13 main::@2 b2: @@ -2302,14 +2310,14 @@ main: { dec $3 //SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda $3 - bne b2_from_b5 + bne b2 //SEG18 main::@3 b3: //SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec $2 //SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda $2 - bne b1_from_b3 + bne b1 //SEG21 main::@return breturn: //SEG22 [8] return [ ] @@ -2322,17 +2330,16 @@ nest1: { //SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $4 + jmp b1 //SEG26 [9] phi from nest1::@3 to nest1::@1 - b1_from_b3: //SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy //SEG28 nest1::@1 b1: //SEG29 [10] phi from nest1::@1 to nest1::@2 - b2_from_b1: //SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- aby=coby1 lda #$64 + jmp b2 //SEG31 [10] phi from nest1::@5 to nest1::@2 - b2_from_b5: //SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy //SEG33 nest1::@2 b2: @@ -2345,14 +2352,14 @@ nest1: { sbc #$1 //SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby_gt_0_then_la1 cmp #$0 - bne b2_from_b5 + bne b2 //SEG38 nest1::@3 b3: //SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec $4 //SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda $4 - bne b1_from_b3 + bne b1 //SEG41 nest1::@return breturn: //SEG42 [16] return [ main::j#2 main::i#2 ] @@ -2364,17 +2371,16 @@ nest2: { b1_from_nest2: //SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- xby=coby1 ldx #$64 + jmp b1 //SEG46 [17] phi from nest2::@3 to nest2::@1 - b1_from_b3: //SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy //SEG48 nest2::@1 b1: //SEG49 [18] phi from nest2::@1 to nest2::@2 - b2_from_b1: //SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- yby=coby1 ldy #$64 + jmp b2 //SEG51 [18] phi from nest2::@2 to nest2::@2 - b2_from_b2: //SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy //SEG53 nest2::@2 b2: @@ -2384,20 +2390,269 @@ nest2: { dey //SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby_gt_0_then_la1 cpy #$0 - bne b2_from_b2 + bne b2 //SEG57 nest2::@3 b3: //SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby=_dec_xby dex //SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b3 + bne b1 //SEG60 nest2::@return breturn: //SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction b5: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_nest1: +Removing instruction b5: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_nest2: +Removing instruction b3: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $2 + jmp b1 + //SEG6 [1] phi from main::@3 to main::@1 + //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG8 main::@1 + b1: + //SEG9 [2] phi from main::@1 to main::@2 + //SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $3 + jmp b2 + //SEG11 [2] phi from main::@5 to main::@2 + //SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy + //SEG13 main::@2 + b2: + //SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] + jsr nest1 + //SEG15 main::@5 + //SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 + dec $3 + //SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 + lda $3 + bne b2 + //SEG18 main::@3 + //SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 + dec $2 + //SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 + lda $2 + bne b1 + //SEG21 main::@return + //SEG22 [8] return [ ] + rts +} +//SEG23 nest1 +nest1: { + //SEG24 [9] phi from nest1 to nest1::@1 + //SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $4 + jmp b1 + //SEG26 [9] phi from nest1::@3 to nest1::@1 + //SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy + //SEG28 nest1::@1 + b1: + //SEG29 [10] phi from nest1::@1 to nest1::@2 + //SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- aby=coby1 + lda #$64 + jmp b2 + //SEG31 [10] phi from nest1::@5 to nest1::@2 + //SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy + //SEG33 nest1::@2 + b2: + //SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] + jsr nest2 + //SEG35 nest1::@5 + //SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby=_dec_aby + sec + sbc #$1 + //SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby_gt_0_then_la1 + cmp #$0 + bne b2 + //SEG38 nest1::@3 + //SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 + lda $4 + bne b1 + //SEG41 nest1::@return + //SEG42 [16] return [ main::j#2 main::i#2 ] + rts +} +//SEG43 nest2 +nest2: { + //SEG44 [17] phi from nest2 to nest2::@1 + //SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- xby=coby1 + ldx #$64 + jmp b1 + //SEG46 [17] phi from nest2::@3 to nest2::@1 + //SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy + //SEG48 nest2::@1 + b1: + //SEG49 [18] phi from nest2::@1 to nest2::@2 + //SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- yby=coby1 + ldy #$64 + jmp b2 + //SEG51 [18] phi from nest2::@2 to nest2::@2 + //SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy + //SEG53 nest2::@2 + b2: + //SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=yby + sty $400 + //SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby=_dec_yby + dey + //SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby_gt_0_then_la1 + cpy #$0 + bne b2 + //SEG57 nest2::@3 + //SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby=_dec_xby + dex + //SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 + //SEG60 nest2::@return + //SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] + rts +} + +Removing instruction jmp b1 +Removing instruction jmp b2 +Removing instruction jmp b1 +Removing instruction jmp b2 +Removing instruction jmp b1 +Removing instruction jmp b2 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $2 + //SEG6 [1] phi from main::@3 to main::@1 + //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + //SEG8 main::@1 + b1: + //SEG9 [2] phi from main::@1 to main::@2 + //SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $3 + //SEG11 [2] phi from main::@5 to main::@2 + //SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy + //SEG13 main::@2 + b2: + //SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] + jsr nest1 + //SEG15 main::@5 + //SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 + dec $3 + //SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 + lda $3 + bne b2 + //SEG18 main::@3 + //SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 + dec $2 + //SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 + lda $2 + bne b1 + //SEG21 main::@return + //SEG22 [8] return [ ] + rts +} +//SEG23 nest1 +nest1: { + //SEG24 [9] phi from nest1 to nest1::@1 + //SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 + lda #$64 + sta $4 + //SEG26 [9] phi from nest1::@3 to nest1::@1 + //SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy + //SEG28 nest1::@1 + b1: + //SEG29 [10] phi from nest1::@1 to nest1::@2 + //SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- aby=coby1 + lda #$64 + //SEG31 [10] phi from nest1::@5 to nest1::@2 + //SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy + //SEG33 nest1::@2 + b2: + //SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] + jsr nest2 + //SEG35 nest1::@5 + //SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby=_dec_aby + sec + sbc #$1 + //SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby_gt_0_then_la1 + cmp #$0 + bne b2 + //SEG38 nest1::@3 + //SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 + dec $4 + //SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 + lda $4 + bne b1 + //SEG41 nest1::@return + //SEG42 [16] return [ main::j#2 main::i#2 ] + rts +} +//SEG43 nest2 +nest2: { + //SEG44 [17] phi from nest2 to nest2::@1 + //SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- xby=coby1 + ldx #$64 + //SEG46 [17] phi from nest2::@3 to nest2::@1 + //SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy + //SEG48 nest2::@1 + b1: + //SEG49 [18] phi from nest2::@1 to nest2::@2 + //SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- yby=coby1 + ldy #$64 + //SEG51 [18] phi from nest2::@2 to nest2::@2 + //SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy + //SEG53 nest2::@2 + b2: + //SEG54 [19] *((word) 1024) ← (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#2 nest2::i#2 ] -- _star_cowo1=yby + sty $400 + //SEG55 [20] (byte) nest2::j#1 ← -- (byte) nest2::j#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby=_dec_yby + dey + //SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby_gt_0_then_la1 + cpy #$0 + bne b2 + //SEG57 nest2::@3 + //SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby=_dec_xby + dex + //SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b1 + //SEG60 nest2::@return + //SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -2447,114 +2702,94 @@ reg byte y [ nest2::j#2 nest2::j#1 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] phi from main to main::@1 - b1_from_main: //SEG5 [1] phi (byte) main::i#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $2 //SEG6 [1] phi from main::@3 to main::@1 - b1_from_b3: //SEG7 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy //SEG8 main::@1 b1: //SEG9 [2] phi from main::@1 to main::@2 - b2_from_b1: //SEG10 [2] phi (byte) main::j#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $3 //SEG11 [2] phi from main::@5 to main::@2 - b2_from_b5: //SEG12 [2] phi (byte) main::j#2 = (byte) main::j#1 -- register_copy //SEG13 main::@2 b2: //SEG14 [3] call nest1 param-assignment [ main::j#2 main::i#2 ] jsr nest1 //SEG15 main::@5 - b5: //SEG16 [4] (byte) main::j#1 ← -- (byte) main::j#2 [ main::j#1 main::i#2 ] -- zpby1=_dec_zpby1 dec $3 //SEG17 [5] if((byte) main::j#1>(byte) 0) goto main::@2 [ main::j#1 main::i#2 ] -- zpby1_gt_0_then_la1 lda $3 - bne b2_from_b5 + bne b2 //SEG18 main::@3 - b3: //SEG19 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 ] -- zpby1=_dec_zpby1 dec $2 //SEG20 [7] if((byte) main::i#1>(byte) 0) goto main::@1 [ main::i#1 ] -- zpby1_gt_0_then_la1 lda $2 - bne b1_from_b3 + bne b1 //SEG21 main::@return - breturn: //SEG22 [8] return [ ] rts } //SEG23 nest1 nest1: { //SEG24 [9] phi from nest1 to nest1::@1 - b1_from_nest1: //SEG25 [9] phi (byte) nest1::i#2 = (byte) 100 -- zpby1=coby1 lda #$64 sta $4 //SEG26 [9] phi from nest1::@3 to nest1::@1 - b1_from_b3: //SEG27 [9] phi (byte) nest1::i#2 = (byte) nest1::i#1 -- register_copy //SEG28 nest1::@1 b1: //SEG29 [10] phi from nest1::@1 to nest1::@2 - b2_from_b1: //SEG30 [10] phi (byte) nest1::j#2 = (byte) 100 -- aby=coby1 lda #$64 //SEG31 [10] phi from nest1::@5 to nest1::@2 - b2_from_b5: //SEG32 [10] phi (byte) nest1::j#2 = (byte) nest1::j#1 -- register_copy //SEG33 nest1::@2 b2: //SEG34 [11] call nest2 param-assignment [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] jsr nest2 //SEG35 nest1::@5 - b5: //SEG36 [12] (byte) nest1::j#1 ← -- (byte) nest1::j#2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby=_dec_aby sec sbc #$1 //SEG37 [13] if((byte) nest1::j#1>(byte) 0) goto nest1::@2 [ main::j#2 main::i#2 nest1::j#1 nest1::i#2 ] -- aby_gt_0_then_la1 cmp #$0 - bne b2_from_b5 + bne b2 //SEG38 nest1::@3 - b3: //SEG39 [14] (byte) nest1::i#1 ← -- (byte) nest1::i#2 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1=_dec_zpby1 dec $4 //SEG40 [15] if((byte) nest1::i#1>(byte) 0) goto nest1::@1 [ main::j#2 main::i#2 nest1::i#1 ] -- zpby1_gt_0_then_la1 lda $4 - bne b1_from_b3 + bne b1 //SEG41 nest1::@return - breturn: //SEG42 [16] return [ main::j#2 main::i#2 ] rts } //SEG43 nest2 nest2: { //SEG44 [17] phi from nest2 to nest2::@1 - b1_from_nest2: //SEG45 [17] phi (byte) nest2::i#2 = (byte) 100 -- xby=coby1 ldx #$64 //SEG46 [17] phi from nest2::@3 to nest2::@1 - b1_from_b3: //SEG47 [17] phi (byte) nest2::i#2 = (byte) nest2::i#1 -- register_copy //SEG48 nest2::@1 b1: //SEG49 [18] phi from nest2::@1 to nest2::@2 - b2_from_b1: //SEG50 [18] phi (byte) nest2::j#2 = (byte) 100 -- yby=coby1 ldy #$64 //SEG51 [18] phi from nest2::@2 to nest2::@2 - b2_from_b2: //SEG52 [18] phi (byte) nest2::j#2 = (byte) nest2::j#1 -- register_copy //SEG53 nest2::@2 b2: @@ -2564,16 +2799,14 @@ nest2: { dey //SEG56 [21] if((byte) nest2::j#1>(byte) 0) goto nest2::@2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::j#1 nest2::i#2 ] -- yby_gt_0_then_la1 cpy #$0 - bne b2_from_b2 + bne b2 //SEG57 nest2::@3 - b3: //SEG58 [22] (byte) nest2::i#1 ← -- (byte) nest2::i#2 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby=_dec_xby dex //SEG59 [23] if((byte) nest2::i#1>(byte) 0) goto nest2::@1 [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 nest2::i#1 ] -- xby_gt_0_then_la1 cpx #$0 - bne b1_from_b3 + bne b1 //SEG60 nest2::@return - breturn: //SEG61 [24] return [ main::j#2 main::i#2 nest1::j#2 nest1::i#2 ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.asm b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.asm index 35f63d4b3..31e606736 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.asm @@ -1,27 +1,20 @@ -bbegin: jsr main -bend: main: { - b1_from_main: ldy #$0 ldx #$64 b1: dex cpx #$0 bne b2 - breturn: rts b2: cpx #$32 beq !+ bcs b4 !: - b5: dey - b1_from_b5: jmp b1 b4: iny - b1_from_b4: jmp b1 } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log index f0fbbb3f2..def53ba56 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/loopsplit.log @@ -608,7 +608,7 @@ Removing instruction jmp bend Removing instruction jmp b1 Removing instruction jmp breturn Removing instruction jmp b5 -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -662,6 +662,60 @@ main: { jmp b1 } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction breturn: +Removing instruction b5: +Removing instruction b1_from_b5: +Removing instruction b1_from_b4: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::s#3 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG6 [1] phi (byte) main::i#2 = (byte) 100 -- xby=coby1 + ldx #$64 + //SEG7 main::@1 + b1: + //SEG8 [2] (byte) main::i#1 ← -- (byte) main::i#2 [ main::i#1 main::s#3 ] -- xby=_dec_xby + dex + //SEG9 [3] if((byte) main::i#1>(byte) 0) goto main::@2 [ main::i#1 main::s#3 ] -- xby_gt_0_then_la1 + cpx #$0 + bne b2 + //SEG10 main::@return + //SEG11 [4] return [ ] + rts + //SEG12 main::@2 + b2: + //SEG13 [5] if((byte) main::i#1>(byte) 50) goto main::@4 [ main::i#1 main::s#3 ] -- xby_gt_coby1_then_la1 + cpx #$32 + beq !+ + bcs b4 + !: + //SEG14 main::@5 + //SEG15 [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] -- yby=_dec_yby + dey + //SEG16 [1] phi from main::@5 to main::@1 + //SEG17 [1] phi (byte) main::s#3 = (byte) main::s#2 -- register_copy + //SEG18 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + jmp b1 + //SEG19 main::@4 + b4: + //SEG20 [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] -- yby=_inc_yby + iny + //SEG21 [1] phi from main::@4 to main::@1 + //SEG22 [1] phi (byte) main::s#3 = (byte) main::s#1 -- register_copy + //SEG23 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + jmp b1 +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -684,15 +738,12 @@ reg byte y [ main::s#3 main::s#1 main::s#2 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] phi from main to main::@1 - b1_from_main: //SEG5 [1] phi (byte) main::s#3 = (byte) 0 -- yby=coby1 ldy #$0 //SEG6 [1] phi (byte) main::i#2 = (byte) 100 -- xby=coby1 @@ -705,7 +756,6 @@ main: { cpx #$0 bne b2 //SEG10 main::@return - breturn: //SEG11 [4] return [ ] rts //SEG12 main::@2 @@ -716,11 +766,9 @@ main: { bcs b4 !: //SEG14 main::@5 - b5: //SEG15 [6] (byte) main::s#2 ← -- (byte) main::s#3 [ main::i#1 main::s#2 ] -- yby=_dec_yby dey //SEG16 [1] phi from main::@5 to main::@1 - b1_from_b5: //SEG17 [1] phi (byte) main::s#3 = (byte) main::s#2 -- register_copy //SEG18 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp b1 @@ -729,7 +777,6 @@ main: { //SEG20 [7] (byte) main::s#1 ← ++ (byte) main::s#3 [ main::i#1 main::s#1 ] -- yby=_inc_yby iny //SEG21 [1] phi from main::@4 to main::@1 - b1_from_b4: //SEG22 [1] phi (byte) main::s#3 = (byte) main::s#1 -- register_copy //SEG23 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp b1 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/minus.asm b/src/main/java/dk/camelot64/kickc/test/ref/minus.asm index c028e66ef..91a2c9037 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/minus.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/minus.asm @@ -1,7 +1,4 @@ -bbegin: -b1_from_bbegin: ldx #$5 -b1_from_b1: b1: txa clc @@ -9,5 +6,4 @@ b1: sta $1100,x inx cpx #$a - bcc b1_from_b1 -bend: + bcc b1 diff --git a/src/main/java/dk/camelot64/kickc/test/ref/minus.log b/src/main/java/dk/camelot64/kickc/test/ref/minus.log index 526ce4b77..84faf807b 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/minus.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/minus.log @@ -355,7 +355,7 @@ Uplift Scope [] 31.17: zp byte:2 [ i#2 i#1 ] 22: zp byte:3 [ $1 ] Uplifting [] best 285 combination reg byte x [ i#2 i#1 ] reg byte a [ $1 ] Removing instruction jmp b1 Removing instruction jmp bend -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -383,17 +383,18 @@ b1: //SEG10 @end bend: -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b1 with b1 +Removing instruction b1_from_bbegin: +Removing instruction b1_from_b1: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) i#2 = (byte) 5 -- xby=coby1 ldx #$5 + jmp b1 //SEG3 [0] phi from @1 to @1 -b1_from_b1: //SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy //SEG5 @1 b1: @@ -407,10 +408,60 @@ b1: inx //SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- xby_lt_coby1_then_la1 cpx #$a - bcc b1_from_b1 + bcc b1 //SEG10 @end bend: +Removing instruction bbegin: +Removing instruction bend: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- xby=coby1 + ldx #$5 + jmp b1 +//SEG3 [0] phi from @1 to @1 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG5 @1 +b1: +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- aby=xby_plus_coby1 + txa + clc + adc #$4 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_xby=aby + sta $1100,x +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- xby=xby_plus_1 + inx +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b1 +//SEG10 @end + +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] phi from @begin to @1 +//SEG2 [0] phi (byte) i#2 = (byte) 5 -- xby=coby1 + ldx #$5 +//SEG3 [0] phi from @1 to @1 +//SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy +//SEG5 @1 +b1: +//SEG6 [1] (byte~) $1 ← (byte) i#2 + (byte) 4 [ i#2 $1 ] -- aby=xby_plus_coby1 + txa + clc + adc #$4 +//SEG7 [2] *((word) 4352 + (byte) i#2) ← (byte~) $1 [ i#2 ] -- cowo1_staridx_xby=aby + sta $1100,x +//SEG8 [3] (byte) i#1 ← (byte) i#2 + (byte) 1 [ i#1 ] -- xby=xby_plus_1 + inx +//SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b1 +//SEG10 @end + FINAL SYMBOL TABLE (byte~) $1 reg byte a 22.0 (label) @1 @@ -426,13 +477,10 @@ reg byte a [ $1 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] phi from @begin to @1 -b1_from_bbegin: //SEG2 [0] phi (byte) i#2 = (byte) 5 -- xby=coby1 ldx #$5 //SEG3 [0] phi from @1 to @1 -b1_from_b1: //SEG4 [0] phi (byte) i#2 = (byte) i#1 -- register_copy //SEG5 @1 b1: @@ -446,7 +494,6 @@ b1: inx //SEG9 [4] if((byte) i#1<(byte) 10) goto @1 [ i#1 ] -- xby_lt_coby1_then_la1 cpx #$a - bcc b1_from_b1 + bcc b1 //SEG10 @end -bend: diff --git a/src/main/java/dk/camelot64/kickc/test/ref/modglobal.asm b/src/main/java/dk/camelot64/kickc/test/ref/modglobal.asm index d12901d94..9cbdf382c 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/modglobal.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/modglobal.asm @@ -1,25 +1,17 @@ -bbegin: jsr main -bend: main: { - inccnt_from_main: ldy #$0 ldx #$0 jsr inccnt - b1: sta $400 inx - inccnt_from_b1: jsr inccnt - b2: sta $401 - breturn: rts } inccnt: { inx iny txa - breturn: rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/modglobal.log b/src/main/java/dk/camelot64/kickc/test/ref/modglobal.log index 50cee9d32..d66451813 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/modglobal.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/modglobal.log @@ -810,7 +810,7 @@ Removing instruction jmp b1 Removing instruction jmp b2 Removing instruction jmp breturn Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -867,6 +867,63 @@ inccnt: { rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction inccnt_from_main: +Removing instruction b1: +Removing instruction inccnt_from_b1: +Removing instruction b2: +Removing instruction breturn: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call inccnt param-assignment [ inccnt::return#0 cnt#1 cnt2#1 ] + //SEG5 [9] phi from main to inccnt + //SEG6 [9] phi (byte) cnt2#11 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG7 [9] phi (byte) cnt#12 = (byte) 0 -- xby=coby1 + ldx #$0 + jsr inccnt + //SEG8 main::@1 + //SEG9 [2] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 ] + // (byte~) main::$0 = (byte) inccnt::return#0 // register copy reg byte a + //SEG10 [3] *((word) 1024) ← (byte~) main::$0 [ cnt#1 cnt2#1 ] -- _star_cowo1=aby + sta $400 + //SEG11 [4] (byte) cnt#3 ← ++ (byte) cnt#1 [ cnt#3 cnt2#1 ] -- xby=_inc_xby + inx + //SEG12 [5] call inccnt param-assignment [ inccnt::return#0 ] + //SEG13 [9] phi from main::@1 to inccnt + //SEG14 [9] phi (byte) cnt2#11 = (byte) cnt2#1 -- register_copy + //SEG15 [9] phi (byte) cnt#12 = (byte) cnt#3 -- register_copy + jsr inccnt + //SEG16 main::@2 + //SEG17 [6] (byte~) main::$1 ← (byte) inccnt::return#0 [ main::$1 ] + // (byte~) main::$1 = (byte) inccnt::return#0 // register copy reg byte a + //SEG18 [7] *((word) 1025) ← (byte~) main::$1 [ ] -- _star_cowo1=aby + sta $401 + //SEG19 main::@return + //SEG20 [8] return [ ] + rts +} +//SEG21 inccnt +inccnt: { + //SEG22 [10] (byte) cnt#1 ← ++ (byte) cnt#12 [ cnt#1 cnt2#11 ] -- xby=_inc_xby + inx + //SEG23 [11] (byte) cnt2#1 ← ++ (byte) cnt2#11 [ cnt#1 cnt2#1 ] -- yby=_inc_yby + iny + //SEG24 [12] (byte) inccnt::return#0 ← (byte) cnt#1 [ inccnt::return#0 cnt#1 cnt2#1 ] -- aby=xby + txa + //SEG25 inccnt::@return + //SEG26 [13] return [ inccnt::return#0 cnt#1 cnt2#1 ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -898,23 +955,19 @@ reg byte a [ inccnt::return#0 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call inccnt param-assignment [ inccnt::return#0 cnt#1 cnt2#1 ] //SEG5 [9] phi from main to inccnt - inccnt_from_main: //SEG6 [9] phi (byte) cnt2#11 = (byte) 0 -- yby=coby1 ldy #$0 //SEG7 [9] phi (byte) cnt#12 = (byte) 0 -- xby=coby1 ldx #$0 jsr inccnt //SEG8 main::@1 - b1: //SEG9 [2] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 ] // (byte~) main::$0 = (byte) inccnt::return#0 // register copy reg byte a //SEG10 [3] *((word) 1024) ← (byte~) main::$0 [ cnt#1 cnt2#1 ] -- _star_cowo1=aby @@ -923,18 +976,15 @@ main: { inx //SEG12 [5] call inccnt param-assignment [ inccnt::return#0 ] //SEG13 [9] phi from main::@1 to inccnt - inccnt_from_b1: //SEG14 [9] phi (byte) cnt2#11 = (byte) cnt2#1 -- register_copy //SEG15 [9] phi (byte) cnt#12 = (byte) cnt#3 -- register_copy jsr inccnt //SEG16 main::@2 - b2: //SEG17 [6] (byte~) main::$1 ← (byte) inccnt::return#0 [ main::$1 ] // (byte~) main::$1 = (byte) inccnt::return#0 // register copy reg byte a //SEG18 [7] *((word) 1025) ← (byte~) main::$1 [ ] -- _star_cowo1=aby sta $401 //SEG19 main::@return - breturn: //SEG20 [8] return [ ] rts } @@ -947,7 +997,6 @@ inccnt: { //SEG24 [12] (byte) inccnt::return#0 ← (byte) cnt#1 [ inccnt::return#0 cnt#1 cnt2#1 ] -- aby=xby txa //SEG25 inccnt::@return - breturn: //SEG26 [13] return [ inccnt::return#0 cnt#1 cnt2#1 ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.asm b/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.asm index 91311dae2..5b58dd2ff 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.asm @@ -1,23 +1,15 @@ -bbegin: jsr main -bend: main: { - inccnt_from_main: ldx #$0 jsr inccnt - b1: stx $400 inx - inccnt_from_b1: jsr inccnt - b2: inx stx $401 - breturn: rts } inccnt: { inx - breturn: rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.log b/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.log index b0655c8f5..dfe258cbc 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/modglobalmin.log @@ -636,7 +636,7 @@ Removing instruction jmp b1 Removing instruction jmp b2 Removing instruction jmp breturn Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -684,6 +684,54 @@ inccnt: { rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction inccnt_from_main: +Removing instruction b1: +Removing instruction inccnt_from_b1: +Removing instruction b2: +Removing instruction breturn: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call inccnt param-assignment [ cnt#10 ] + //SEG5 [8] phi from main to inccnt + //SEG6 [8] phi (byte) cnt#13 = (byte) 0 -- xby=coby1 + ldx #$0 + jsr inccnt + //SEG7 main::@1 + //SEG8 [2] *((word) 1024) ← (byte) cnt#10 [ cnt#10 ] -- _star_cowo1=xby + stx $400 + //SEG9 [3] (byte) cnt#3 ← ++ (byte) cnt#10 [ cnt#3 ] -- xby=_inc_xby + inx + //SEG10 [4] call inccnt param-assignment [ cnt#10 ] + //SEG11 [8] phi from main::@1 to inccnt + //SEG12 [8] phi (byte) cnt#13 = (byte) cnt#3 -- register_copy + jsr inccnt + //SEG13 main::@2 + //SEG14 [5] (byte) cnt#1 ← ++ (byte) cnt#10 [ cnt#1 ] -- xby=_inc_xby + inx + //SEG15 [6] *((word) 1025) ← (byte) cnt#1 [ ] -- _star_cowo1=xby + stx $401 + //SEG16 main::@return + //SEG17 [7] return [ ] + rts +} +//SEG18 inccnt +inccnt: { + //SEG19 [9] (byte) cnt#10 ← ++ (byte) cnt#13 [ cnt#10 ] -- xby=_inc_xby + inx + //SEG20 inccnt::@return + //SEG21 [10] return [ cnt#10 ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -706,38 +754,31 @@ reg byte x [ cnt#10 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call inccnt param-assignment [ cnt#10 ] //SEG5 [8] phi from main to inccnt - inccnt_from_main: //SEG6 [8] phi (byte) cnt#13 = (byte) 0 -- xby=coby1 ldx #$0 jsr inccnt //SEG7 main::@1 - b1: //SEG8 [2] *((word) 1024) ← (byte) cnt#10 [ cnt#10 ] -- _star_cowo1=xby stx $400 //SEG9 [3] (byte) cnt#3 ← ++ (byte) cnt#10 [ cnt#3 ] -- xby=_inc_xby inx //SEG10 [4] call inccnt param-assignment [ cnt#10 ] //SEG11 [8] phi from main::@1 to inccnt - inccnt_from_b1: //SEG12 [8] phi (byte) cnt#13 = (byte) cnt#3 -- register_copy jsr inccnt //SEG13 main::@2 - b2: //SEG14 [5] (byte) cnt#1 ← ++ (byte) cnt#10 [ cnt#1 ] -- xby=_inc_xby inx //SEG15 [6] *((word) 1025) ← (byte) cnt#1 [ ] -- _star_cowo1=xby stx $401 //SEG16 main::@return - breturn: //SEG17 [7] return [ ] rts } @@ -746,7 +787,6 @@ inccnt: { //SEG19 [9] (byte) cnt#10 ← ++ (byte) cnt#13 [ cnt#10 ] -- xby=_inc_xby inx //SEG20 inccnt::@return - breturn: //SEG21 [10] return [ cnt#10 ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm index 5fbb09c93..a28305928 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.asm @@ -1,19 +1,12 @@ -bbegin: jsr main -bend: main: { jsr lvalue - b1: jsr rvalue - b2: jsr rvaluevar - b3: jsr lvaluevar - breturn: rts } lvaluevar: { - b1_from_lvaluevar: lda #<$400 sta $2 lda #>$400 @@ -22,7 +15,6 @@ lvaluevar: { b1: cpx #$a bcc b2 - breturn: rts b2: ldy #$0 @@ -33,11 +25,9 @@ lvaluevar: { inc $2+$1 !: inx - b1_from_b2: jmp b1 } rvaluevar: { - b1_from_rvaluevar: lda #<$400 sta $2 lda #>$400 @@ -46,7 +36,6 @@ rvaluevar: { b1: cpx #$a bcc b2 - breturn: rts b2: ldy #$0 @@ -56,23 +45,19 @@ rvaluevar: { inc $2+$1 !: inx - b1_from_b2: jmp b1 } rvalue: { lda $400 lda $401 - b1_from_rvalue: ldx #$2 b1: cpx #$a bcc b2 - breturn: rts b2: lda $400,x inx - b1_from_b2: jmp b1 } lvalue: { @@ -80,17 +65,14 @@ lvalue: { sta $400 lda #$2 sta $401 - b1_from_lvalue: ldx #$2 b1: cpx #$a bcc b2 - breturn: rts b2: lda #$3 sta $400,x inx - b1_from_b2: jmp b1 } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log index 6be234d8d..8f3ceb921 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/ptrtest.log @@ -2129,7 +2129,7 @@ Removing instruction jmp b1 Removing instruction jmp breturn Removing instruction jmp b1 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -2299,6 +2299,176 @@ lvalue: { jmp b1 } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1: +Removing instruction b2: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_lvaluevar: +Removing instruction breturn: +Removing instruction b1_from_b2: +Removing instruction b1_from_rvaluevar: +Removing instruction breturn: +Removing instruction b1_from_b2: +Removing instruction b1_from_rvalue: +Removing instruction breturn: +Removing instruction b1_from_b2: +Removing instruction b1_from_lvalue: +Removing instruction breturn: +Removing instruction b1_from_b2: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call lvalue param-assignment [ ] + jsr lvalue + //SEG5 main::@1 + //SEG6 [2] call rvalue param-assignment [ ] + jsr rvalue + //SEG7 main::@2 + //SEG8 [3] call rvaluevar param-assignment [ ] + jsr rvaluevar + //SEG9 main::@3 + //SEG10 [4] call lvaluevar param-assignment [ ] + jsr lvaluevar + //SEG11 main::@return + //SEG12 [5] return [ ] + rts +} +//SEG13 lvaluevar +lvaluevar: { + //SEG14 [6] phi from lvaluevar to lvaluevar::@1 + //SEG15 [6] phi (byte*) lvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $2 + lda #>$400 + sta $2+$1 + //SEG16 [6] phi (byte) lvaluevar::i#2 = (byte) 2 -- xby=coby1 + ldx #$2 + //SEG17 lvaluevar::@1 + b1: + //SEG18 [7] if((byte) lvaluevar::i#2<(byte) 10) goto lvaluevar::@2 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b2 + //SEG19 lvaluevar::@return + //SEG20 [8] return [ ] + rts + //SEG21 lvaluevar::@2 + b2: + //SEG22 [9] *((byte*) lvaluevar::screen#2) ← (byte) 4 [ lvaluevar::i#2 lvaluevar::screen#2 ] -- _star_zpptrby1=coby1 + ldy #$0 + lda #$4 + sta ($2),y + //SEG23 [10] (byte*) lvaluevar::screen#1 ← ++ (byte*) lvaluevar::screen#2 [ lvaluevar::screen#1 lvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 + inc $2 + bne !+ + inc $2+$1 + !: + //SEG24 [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] -- xby=_inc_xby + inx + //SEG25 [6] phi from lvaluevar::@2 to lvaluevar::@1 + //SEG26 [6] phi (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 -- register_copy + //SEG27 [6] phi (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 -- register_copy + jmp b1 +} +//SEG28 rvaluevar +rvaluevar: { + //SEG29 [12] phi from rvaluevar to rvaluevar::@1 + //SEG30 [12] phi (byte*) rvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $2 + lda #>$400 + sta $2+$1 + //SEG31 [12] phi (byte) rvaluevar::i#2 = (byte) 2 -- xby=coby1 + ldx #$2 + //SEG32 rvaluevar::@1 + b1: + //SEG33 [13] if((byte) rvaluevar::i#2<(byte) 10) goto rvaluevar::@2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b2 + //SEG34 rvaluevar::@return + //SEG35 [14] return [ ] + rts + //SEG36 rvaluevar::@2 + b2: + //SEG37 [15] (byte) rvaluevar::b#0 ← * (byte*) rvaluevar::screen#2 [ rvaluevar::i#2 rvaluevar::screen#2 ] -- aby=_star_zpptrby1 + ldy #$0 + lda ($2),y + //SEG38 [16] (byte*) rvaluevar::screen#1 ← ++ (byte*) rvaluevar::screen#2 [ rvaluevar::screen#1 rvaluevar::i#2 ] -- zpptrby1=_inc_zpptrby1 + inc $2 + bne !+ + inc $2+$1 + !: + //SEG39 [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] -- xby=_inc_xby + inx + //SEG40 [12] phi from rvaluevar::@2 to rvaluevar::@1 + //SEG41 [12] phi (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 -- register_copy + //SEG42 [12] phi (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 -- register_copy + jmp b1 +} +//SEG43 rvalue +rvalue: { + //SEG44 [18] (byte) rvalue::b#0 ← * (word) 1024 [ ] -- aby=_star_cowo1 + lda $400 + //SEG45 [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] -- aby=_star_cowo1 + lda $401 + //SEG46 [20] phi from rvalue to rvalue::@1 + //SEG47 [20] phi (byte) rvalue::i#2 = (byte) 2 -- xby=coby1 + ldx #$2 + //SEG48 rvalue::@1 + b1: + //SEG49 [21] if((byte) rvalue::i#2<(byte) 10) goto rvalue::@2 [ rvalue::i#2 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b2 + //SEG50 rvalue::@return + //SEG51 [22] return [ ] + rts + //SEG52 rvalue::@2 + b2: + //SEG53 [23] (byte) rvalue::b#2 ← (word) 1024 *idx (byte) rvalue::i#2 [ rvalue::i#2 ] -- aby=cowo1_staridx_xby + lda $400,x + //SEG54 [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] -- xby=_inc_xby + inx + //SEG55 [20] phi from rvalue::@2 to rvalue::@1 + //SEG56 [20] phi (byte) rvalue::i#2 = (byte) rvalue::i#1 -- register_copy + jmp b1 +} +//SEG57 lvalue +lvalue: { + //SEG58 [25] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 + lda #$1 + sta $400 + //SEG59 [26] *((word) 1025) ← (byte) 2 [ ] -- _star_cowo1=coby2 + lda #$2 + sta $401 + //SEG60 [27] phi from lvalue to lvalue::@1 + //SEG61 [27] phi (byte) lvalue::i#2 = (byte) 2 -- xby=coby1 + ldx #$2 + //SEG62 lvalue::@1 + b1: + //SEG63 [28] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b2 + //SEG64 lvalue::@return + //SEG65 [29] return [ ] + rts + //SEG66 lvalue::@2 + b2: + //SEG67 [30] *((word) 1024 + (byte) lvalue::i#2) ← (byte) 3 [ lvalue::i#2 ] -- cowo1_staridx_xby=coby2 + lda #$3 + sta $400,x + //SEG68 [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] -- xby=_inc_xby + inx + //SEG69 [27] phi from lvalue::@2 to lvalue::@1 + //SEG70 [27] phi (byte) lvalue::i#2 = (byte) lvalue::i#1 -- register_copy + jmp b1 +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -2363,36 +2533,29 @@ reg byte a [ rvalue::b#2 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call lvalue param-assignment [ ] jsr lvalue //SEG5 main::@1 - b1: //SEG6 [2] call rvalue param-assignment [ ] jsr rvalue //SEG7 main::@2 - b2: //SEG8 [3] call rvaluevar param-assignment [ ] jsr rvaluevar //SEG9 main::@3 - b3: //SEG10 [4] call lvaluevar param-assignment [ ] jsr lvaluevar //SEG11 main::@return - breturn: //SEG12 [5] return [ ] rts } //SEG13 lvaluevar lvaluevar: { //SEG14 [6] phi from lvaluevar to lvaluevar::@1 - b1_from_lvaluevar: //SEG15 [6] phi (byte*) lvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<$400 sta $2 @@ -2406,7 +2569,6 @@ lvaluevar: { cpx #$a bcc b2 //SEG19 lvaluevar::@return - breturn: //SEG20 [8] return [ ] rts //SEG21 lvaluevar::@2 @@ -2423,7 +2585,6 @@ lvaluevar: { //SEG24 [11] (byte) lvaluevar::i#1 ← ++ (byte) lvaluevar::i#2 [ lvaluevar::i#1 lvaluevar::screen#1 ] -- xby=_inc_xby inx //SEG25 [6] phi from lvaluevar::@2 to lvaluevar::@1 - b1_from_b2: //SEG26 [6] phi (byte*) lvaluevar::screen#2 = (byte*) lvaluevar::screen#1 -- register_copy //SEG27 [6] phi (byte) lvaluevar::i#2 = (byte) lvaluevar::i#1 -- register_copy jmp b1 @@ -2431,7 +2592,6 @@ lvaluevar: { //SEG28 rvaluevar rvaluevar: { //SEG29 [12] phi from rvaluevar to rvaluevar::@1 - b1_from_rvaluevar: //SEG30 [12] phi (byte*) rvaluevar::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<$400 sta $2 @@ -2445,7 +2605,6 @@ rvaluevar: { cpx #$a bcc b2 //SEG34 rvaluevar::@return - breturn: //SEG35 [14] return [ ] rts //SEG36 rvaluevar::@2 @@ -2461,7 +2620,6 @@ rvaluevar: { //SEG39 [17] (byte) rvaluevar::i#1 ← ++ (byte) rvaluevar::i#2 [ rvaluevar::i#1 rvaluevar::screen#1 ] -- xby=_inc_xby inx //SEG40 [12] phi from rvaluevar::@2 to rvaluevar::@1 - b1_from_b2: //SEG41 [12] phi (byte*) rvaluevar::screen#2 = (byte*) rvaluevar::screen#1 -- register_copy //SEG42 [12] phi (byte) rvaluevar::i#2 = (byte) rvaluevar::i#1 -- register_copy jmp b1 @@ -2473,7 +2631,6 @@ rvalue: { //SEG45 [19] (byte) rvalue::b#1 ← * (word) 1025 [ ] -- aby=_star_cowo1 lda $401 //SEG46 [20] phi from rvalue to rvalue::@1 - b1_from_rvalue: //SEG47 [20] phi (byte) rvalue::i#2 = (byte) 2 -- xby=coby1 ldx #$2 //SEG48 rvalue::@1 @@ -2482,7 +2639,6 @@ rvalue: { cpx #$a bcc b2 //SEG50 rvalue::@return - breturn: //SEG51 [22] return [ ] rts //SEG52 rvalue::@2 @@ -2492,7 +2648,6 @@ rvalue: { //SEG54 [24] (byte) rvalue::i#1 ← ++ (byte) rvalue::i#2 [ rvalue::i#1 ] -- xby=_inc_xby inx //SEG55 [20] phi from rvalue::@2 to rvalue::@1 - b1_from_b2: //SEG56 [20] phi (byte) rvalue::i#2 = (byte) rvalue::i#1 -- register_copy jmp b1 } @@ -2505,7 +2660,6 @@ lvalue: { lda #$2 sta $401 //SEG60 [27] phi from lvalue to lvalue::@1 - b1_from_lvalue: //SEG61 [27] phi (byte) lvalue::i#2 = (byte) 2 -- xby=coby1 ldx #$2 //SEG62 lvalue::@1 @@ -2514,7 +2668,6 @@ lvalue: { cpx #$a bcc b2 //SEG64 lvalue::@return - breturn: //SEG65 [29] return [ ] rts //SEG66 lvalue::@2 @@ -2525,7 +2678,6 @@ lvalue: { //SEG68 [31] (byte) lvalue::i#1 ← ++ (byte) lvalue::i#2 [ lvalue::i#1 ] -- xby=_inc_xby inx //SEG69 [27] phi from lvalue::@2 to lvalue::@1 - b1_from_b2: //SEG70 [27] phi (byte) lvalue::i#2 = (byte) lvalue::i#1 -- register_copy jmp b1 } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.asm b/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.asm index 59d9e5218..e354686a8 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.asm @@ -1,17 +1,12 @@ -bbegin: jsr main -bend: main: { - b1_from_main: ldx #$2 b1: cpx #$a bcc b2 - breturn: rts b2: lda $400,x inx - b1_from_b2: jmp b1 } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.log b/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.log index b1fbfa4c4..465a989e9 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/ptrtestmin.log @@ -504,7 +504,7 @@ Uplifting [] best 235 combination Removing instruction jmp bend Removing instruction jmp b1 Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -539,6 +539,41 @@ main: { jmp b1 } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction breturn: +Removing instruction b1_from_b2: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] phi from main to main::@1 + //SEG5 [1] phi (byte) main::i#2 = (byte) 2 -- xby=coby1 + ldx #$2 + //SEG6 main::@1 + b1: + //SEG7 [2] if((byte) main::i#2<(byte) 10) goto main::@2 [ main::i#2 ] -- xby_lt_coby1_then_la1 + cpx #$a + bcc b2 + //SEG8 main::@return + //SEG9 [3] return [ ] + rts + //SEG10 main::@2 + b2: + //SEG11 [4] (byte) main::b#0 ← (word) 1024 *idx (byte) main::i#2 [ main::i#2 ] -- aby=cowo1_staridx_xby + lda $400,x + //SEG12 [5] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::i#1 ] -- xby=_inc_xby + inx + //SEG13 [1] phi from main::@2 to main::@1 + //SEG14 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy + jmp b1 +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -558,15 +593,12 @@ reg byte a [ main::b#0 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] phi from main to main::@1 - b1_from_main: //SEG5 [1] phi (byte) main::i#2 = (byte) 2 -- xby=coby1 ldx #$2 //SEG6 main::@1 @@ -575,7 +607,6 @@ main: { cpx #$a bcc b2 //SEG8 main::@return - breturn: //SEG9 [3] return [ ] rts //SEG10 main::@2 @@ -585,7 +616,6 @@ main: { //SEG12 [5] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::i#1 ] -- xby=_inc_xby inx //SEG13 [1] phi from main::@2 to main::@1 - b1_from_b2: //SEG14 [1] phi (byte) main::i#2 = (byte) main::i#1 -- register_copy jmp b1 } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/summin.asm b/src/main/java/dk/camelot64/kickc/test/ref/summin.asm index a64cade94..07003ebdf 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/summin.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/summin.asm @@ -1,32 +1,23 @@ -bbegin: -sum_from_bbegin: lda #$2 ldy #$1 jsr sum -b2: sta $2 -sum_from_b2: lda #$4 ldy #$3 jsr sum -b3: tax -sum_from_b3: lda #$d ldy #$9 jsr sum -b4: sta $3 txa clc adc $2 clc adc $3 -bend: sum: { sty $ff clc adc $ff - breturn: rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/summin.log b/src/main/java/dk/camelot64/kickc/test/ref/summin.log index f429f9510..e20faf477 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/summin.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/summin.log @@ -597,7 +597,7 @@ Removing instruction jmp b3 Removing instruction jmp b4 Removing instruction jmp bend Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -658,45 +658,13 @@ sum: { rts } -FINAL SYMBOL TABLE -(byte~) $3 reg byte a 4.0 -(label) @2 -(label) @3 -(label) @4 -(label) @begin -(label) @end -(byte) s1 -(byte) s1#0 zp byte:2 0.5 -(byte) s2 -(byte) s2#0 reg byte x 0.6666666666666666 -(byte) s3 -(byte) s3#0 zp byte:3 2.0 -(byte) s4 -(byte) s4#0 reg byte a Infinity -(byte()) sum((byte) sum::a , (byte) sum::b) -(label) sum::@return -(byte) sum::a -(byte) sum::a#3 reg byte y 2.0 -(byte) sum::b -(byte) sum::b#3 reg byte a 2.0 -(byte) sum::return -(byte) sum::return#0 reg byte a 1.6 - -reg byte y [ sum::a#3 ] -reg byte a [ sum::b#3 ] -zp byte:2 [ s1#0 ] -reg byte x [ s2#0 ] -zp byte:3 [ s3#0 ] -reg byte a [ $3 ] -reg byte a [ s4#0 ] -reg byte a [ sum::return#0 ] - -FINAL CODE +Removing instruction sum_from_bbegin: +Succesful ASM optimization Pass6RedundantLabelElimination +ASSEMBLER //SEG0 @begin bbegin: //SEG1 [0] call sum param-assignment [ sum::return#0 ] //SEG2 [8] phi from @begin to sum -sum_from_bbegin: //SEG3 [8] phi (byte) sum::b#3 = (byte) 2 -- aby=coby1 lda #$2 //SEG4 [8] phi (byte) sum::a#3 = (byte) 1 -- yby=coby1 @@ -751,3 +719,147 @@ sum: { rts } +Removing instruction bbegin: +Removing instruction b2: +Removing instruction sum_from_b2: +Removing instruction b3: +Removing instruction sum_from_b3: +Removing instruction b4: +Removing instruction bend: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call sum param-assignment [ sum::return#0 ] +//SEG2 [8] phi from @begin to sum +//SEG3 [8] phi (byte) sum::b#3 = (byte) 2 -- aby=coby1 + lda #$2 +//SEG4 [8] phi (byte) sum::a#3 = (byte) 1 -- yby=coby1 + ldy #$1 + jsr sum +//SEG5 @2 +//SEG6 [1] (byte) s1#0 ← (byte) sum::return#0 [ s1#0 ] -- zpby1=aby + sta $2 +//SEG7 [2] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG8 [8] phi from @2 to sum +//SEG9 [8] phi (byte) sum::b#3 = (byte) 4 -- aby=coby1 + lda #$4 +//SEG10 [8] phi (byte) sum::a#3 = (byte) 3 -- yby=coby1 + ldy #$3 + jsr sum +//SEG11 @3 +//SEG12 [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] -- xby=aby + tax +//SEG13 [4] call sum param-assignment [ sum::return#0 s1#0 s2#0 ] +//SEG14 [8] phi from @3 to sum +//SEG15 [8] phi (byte) sum::b#3 = (byte) 13 -- aby=coby1 + lda #$d +//SEG16 [8] phi (byte) sum::a#3 = (byte) 9 -- yby=coby1 + ldy #$9 + jsr sum +//SEG17 @4 +//SEG18 [5] (byte) s3#0 ← (byte) sum::return#0 [ s1#0 s2#0 s3#0 ] -- zpby1=aby + sta $3 +//SEG19 [6] (byte~) $3 ← (byte) s1#0 + (byte) s2#0 [ $3 s3#0 ] -- aby=zpby1_plus_xby + txa + clc + adc $2 +//SEG20 [7] (byte) s4#0 ← (byte~) $3 + (byte) s3#0 [ ] -- aby=aby_plus_zpby1 + clc + adc $3 +//SEG21 @end +//SEG22 sum +sum: { + //SEG23 [9] (byte) sum::return#0 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#0 s1#0 s2#0 ] -- aby=yby_plus_aby + sty $ff + clc + adc $ff + //SEG24 sum::@return + //SEG25 [10] return [ sum::return#0 s1#0 s2#0 ] + rts +} + +FINAL SYMBOL TABLE +(byte~) $3 reg byte a 4.0 +(label) @2 +(label) @3 +(label) @4 +(label) @begin +(label) @end +(byte) s1 +(byte) s1#0 zp byte:2 0.5 +(byte) s2 +(byte) s2#0 reg byte x 0.6666666666666666 +(byte) s3 +(byte) s3#0 zp byte:3 2.0 +(byte) s4 +(byte) s4#0 reg byte a Infinity +(byte()) sum((byte) sum::a , (byte) sum::b) +(label) sum::@return +(byte) sum::a +(byte) sum::a#3 reg byte y 2.0 +(byte) sum::b +(byte) sum::b#3 reg byte a 2.0 +(byte) sum::return +(byte) sum::return#0 reg byte a 1.6 + +reg byte y [ sum::a#3 ] +reg byte a [ sum::b#3 ] +zp byte:2 [ s1#0 ] +reg byte x [ s2#0 ] +zp byte:3 [ s3#0 ] +reg byte a [ $3 ] +reg byte a [ s4#0 ] +reg byte a [ sum::return#0 ] + +FINAL CODE +//SEG0 @begin +//SEG1 [0] call sum param-assignment [ sum::return#0 ] +//SEG2 [8] phi from @begin to sum +//SEG3 [8] phi (byte) sum::b#3 = (byte) 2 -- aby=coby1 + lda #$2 +//SEG4 [8] phi (byte) sum::a#3 = (byte) 1 -- yby=coby1 + ldy #$1 + jsr sum +//SEG5 @2 +//SEG6 [1] (byte) s1#0 ← (byte) sum::return#0 [ s1#0 ] -- zpby1=aby + sta $2 +//SEG7 [2] call sum param-assignment [ sum::return#0 s1#0 ] +//SEG8 [8] phi from @2 to sum +//SEG9 [8] phi (byte) sum::b#3 = (byte) 4 -- aby=coby1 + lda #$4 +//SEG10 [8] phi (byte) sum::a#3 = (byte) 3 -- yby=coby1 + ldy #$3 + jsr sum +//SEG11 @3 +//SEG12 [3] (byte) s2#0 ← (byte) sum::return#0 [ s1#0 s2#0 ] -- xby=aby + tax +//SEG13 [4] call sum param-assignment [ sum::return#0 s1#0 s2#0 ] +//SEG14 [8] phi from @3 to sum +//SEG15 [8] phi (byte) sum::b#3 = (byte) 13 -- aby=coby1 + lda #$d +//SEG16 [8] phi (byte) sum::a#3 = (byte) 9 -- yby=coby1 + ldy #$9 + jsr sum +//SEG17 @4 +//SEG18 [5] (byte) s3#0 ← (byte) sum::return#0 [ s1#0 s2#0 s3#0 ] -- zpby1=aby + sta $3 +//SEG19 [6] (byte~) $3 ← (byte) s1#0 + (byte) s2#0 [ $3 s3#0 ] -- aby=zpby1_plus_xby + txa + clc + adc $2 +//SEG20 [7] (byte) s4#0 ← (byte~) $3 + (byte) s3#0 [ ] -- aby=aby_plus_zpby1 + clc + adc $3 +//SEG21 @end +//SEG22 sum +sum: { + //SEG23 [9] (byte) sum::return#0 ← (byte) sum::a#3 + (byte) sum::b#3 [ sum::return#0 s1#0 s2#0 ] -- aby=yby_plus_aby + sty $ff + clc + adc $ff + //SEG24 sum::@return + //SEG25 [10] return [ sum::return#0 s1#0 s2#0 ] + rts +} + diff --git a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.asm b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.asm index 2c6f7cbcb..b3462cb4d 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.asm @@ -1,9 +1,6 @@ -bbegin: jsr main -bend: main: { lda #$1 sta $400 - breturn: rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log index f4a83a4f9..d26a2099b 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/useglobal.log @@ -240,7 +240,7 @@ Uplifting [main] best 24 combination Uplifting [] best 24 combination Removing instruction jmp bend Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -259,6 +259,25 @@ main: { rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 + lda #$1 + sta $400 + //SEG5 main::@return + //SEG6 [2] return [ ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -269,18 +288,15 @@ FINAL SYMBOL TABLE FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] *((word) 1024) ← (byte) 1 [ ] -- _star_cowo1=coby2 lda #$1 sta $400 //SEG5 main::@return - breturn: //SEG6 [2] return [ ] rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/voronoi.asm b/src/main/java/dk/camelot64/kickc/test/ref/voronoi.asm index 169470619..9f101652d 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/voronoi.asm +++ b/src/main/java/dk/camelot64/kickc/test/ref/voronoi.asm @@ -1,8 +1,5 @@ -bbegin: jsr main -bend: main: { - addpoint_from_main: lda #$1 sta $2 ldy #$5 @@ -10,50 +7,36 @@ main: { sta $8 lda #$5 jsr addpoint - b3: - addpoint_from_b3: lda #$2 sta $2 ldy #$8 lda #$f jsr addpoint - b4: - addpoint_from_b4: lda #$3 sta $2 ldy #$e lda #$6 jsr addpoint - b5: - addpoint_from_b5: lda #$4 sta $2 ldy #$2 lda #$22 jsr addpoint - b6: - addpoint_from_b6: lda #$5 sta $2 ldy #$11 lda #$15 jsr addpoint - b7: - addpoint_from_b7: lda #$7 sta $2 ldy #$16 lda #$1f jsr addpoint - b8: jsr initscreen b1: jsr render - b10: jsr animate - b11: jmp b1 - breturn: rts } animate: { @@ -131,34 +114,28 @@ animate: { jmp b2 } render: { - b1_from_render: lda #<$d800 sta $3 lda #>$d800 sta $3+$1 lda #$0 sta $2 - b1_from_b3: b1: - b2_from_b1: lda #$0 sta $5 - b2_from_b5: b2: lda $5 sta $9 lda $2 sta $a jsr findcol - b5: tya ldy $5 sta ($3),y inc $5 lda $5 cmp #$28 - bcc b2_from_b5 - b3: + bcc b2 lda $3 clc adc #$28 @@ -169,17 +146,14 @@ render: { inc $2 lda $2 cmp #$19 - bcc b1_from_b3 - breturn: + bcc b1 rts } findcol: { - b1_from_findcol: ldy #$0 lda #$ff sta $6 ldx #$0 - b1_from_b13: b1: lda $1000,x sta $7 @@ -192,32 +166,26 @@ findcol: { lda $9 cmp $7 bcc b6 - b7: lda $9 sec sbc $7 sta $7 - b8_from_b7: b8: lda $a cmp $b bcc b9 - b10: lda $a sec sbc $b clc adc $7 - b11_from_b10: b11: cmp $6 bcc b12 - b13_from_b11: b13: inx cpx $8 - bcc b1_from_b13 - breturn_from_b13: + bcc b1 jmp breturn breturn_from_b2: ldy #$0 @@ -226,7 +194,6 @@ findcol: { b12: ldy $1200,x sta $6 - b13_from_b12: jmp b13 b9: lda $b @@ -234,14 +201,12 @@ findcol: { sbc $a clc adc $7 - b11_from_b9: jmp b11 b6: lda $7 sec sbc $9 sta $7 - b8_from_b6: jmp b8 b2: lda $a @@ -250,12 +215,10 @@ findcol: { jmp b3 } initscreen: { - b1_from_initscreen: lda #<$400 sta $3 lda #>$400 sta $3+$1 - b1_from_b1: b1: ldy #$0 lda #$e6 @@ -266,13 +229,12 @@ initscreen: { !: lda $3+$1 cmp #>$7e8 - bcc b1_from_b1 + bcc b1 bne !+ lda $3 cmp #<$7e8 - bcc b1_from_b1 + bcc b1 !: - breturn: rts } addpoint: { @@ -285,6 +247,5 @@ addpoint: { ldx $8 sta $1200,x inc $8 - breturn: rts } diff --git a/src/main/java/dk/camelot64/kickc/test/ref/voronoi.log b/src/main/java/dk/camelot64/kickc/test/ref/voronoi.log index af0e150ee..ba7140c26 100644 --- a/src/main/java/dk/camelot64/kickc/test/ref/voronoi.log +++ b/src/main/java/dk/camelot64/kickc/test/ref/voronoi.log @@ -7523,7 +7523,7 @@ Removing instruction jmp breturn Removing instruction jmp b1 Removing instruction jmp breturn Removing instruction jmp breturn -Succesful ASM optimization Pass5NextJumpElimination +Succesful ASM optimization Pass6NextJumpElimination ASSEMBLER //SEG0 @begin bbegin: @@ -8028,11 +8028,25 @@ addpoint: { rts } -Removing instruction jmp b1 -Removing instruction jmp b2 -Removing instruction jmp b1 -Removing instruction jmp b1 -Succesful ASM optimization Pass5NextJumpElimination +Replacing label b2_from_b5 with b2 +Replacing label b1_from_b3 with b1 +Replacing label b1_from_b13 with b1 +Replacing label b1_from_b1 with b1 +Replacing label b1_from_b1 with b1 +Removing instruction addpoint_from_b3: +Removing instruction addpoint_from_b4: +Removing instruction addpoint_from_b5: +Removing instruction addpoint_from_b6: +Removing instruction addpoint_from_b7: +Removing instruction b1_from_b3: +Removing instruction b2_from_b1: +Removing instruction b2_from_b5: +Removing instruction b1_from_b13: +Removing instruction b8_from_b7: +Removing instruction b11_from_b10: +Removing instruction b13_from_b11: +Removing instruction b1_from_b1: +Succesful ASM optimization Pass6RedundantLabelElimination ASSEMBLER //SEG0 @begin bbegin: @@ -8060,7 +8074,6 @@ main: { b3: //SEG11 [2] call addpoint param-assignment [ ] //SEG12 [92] phi from main::@3 to addpoint - addpoint_from_b3: //SEG13 [92] phi (byte) addpoint::c#6 = (byte) 2 -- zpby1=coby1 lda #$2 sta $2 @@ -8074,7 +8087,6 @@ main: { b4: //SEG18 [3] call addpoint param-assignment [ ] //SEG19 [92] phi from main::@4 to addpoint - addpoint_from_b4: //SEG20 [92] phi (byte) addpoint::c#6 = (byte) 3 -- zpby1=coby1 lda #$3 sta $2 @@ -8088,7 +8100,6 @@ main: { b5: //SEG25 [4] call addpoint param-assignment [ ] //SEG26 [92] phi from main::@5 to addpoint - addpoint_from_b5: //SEG27 [92] phi (byte) addpoint::c#6 = (byte) 4 -- zpby1=coby1 lda #$4 sta $2 @@ -8102,7 +8113,6 @@ main: { b6: //SEG32 [5] call addpoint param-assignment [ ] //SEG33 [92] phi from main::@6 to addpoint - addpoint_from_b6: //SEG34 [92] phi (byte) addpoint::c#6 = (byte) 5 -- zpby1=coby1 lda #$5 sta $2 @@ -8116,7 +8126,6 @@ main: { b7: //SEG39 [6] call addpoint param-assignment [ ] //SEG40 [92] phi from main::@7 to addpoint - addpoint_from_b7: //SEG41 [92] phi (byte) addpoint::c#6 = (byte) 7 -- zpby1=coby1 lda #$7 sta $2 @@ -8284,19 +8293,18 @@ render: { //SEG109 [51] phi (byte) render::y#2 = (byte) 0 -- zpby1=coby1 lda #$0 sta $2 + jmp b1 //SEG110 [51] phi from render::@3 to render::@1 - b1_from_b3: //SEG111 [51] phi (byte*) render::colline#2 = (byte*) render::colline#1 -- register_copy //SEG112 [51] phi (byte) render::y#2 = (byte) render::y#1 -- register_copy //SEG113 render::@1 b1: //SEG114 [52] phi from render::@1 to render::@2 - b2_from_b1: //SEG115 [52] phi (byte) render::x#2 = (byte) 0 -- zpby1=coby1 lda #$0 sta $5 + jmp b2 //SEG116 [52] phi from render::@5 to render::@2 - b2_from_b5: //SEG117 [52] phi (byte) render::x#2 = (byte) render::x#1 -- register_copy //SEG118 render::@2 b2: @@ -8320,7 +8328,7 @@ render: { //SEG126 [59] if((byte) render::x#1<(byte) 40) goto render::@2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1_lt_coby1_then_la1 lda $5 cmp #$28 - bcc b2_from_b5 + bcc b2 //SEG127 render::@3 b3: //SEG128 [60] (byte*) render::colline#1 ← (byte*) render::colline#2 + (byte) 40 [ render::colline#1 render::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 @@ -8336,7 +8344,7 @@ render: { //SEG130 [62] if((byte) render::y#1<(byte) 25) goto render::@1 [ render::y#1 render::colline#1 ] -- zpby1_lt_coby1_then_la1 lda $2 cmp #$19 - bcc b1_from_b3 + bcc b1 //SEG131 render::@return breturn: //SEG132 [63] return [ ] @@ -8353,8 +8361,8 @@ findcol: { sta $6 //SEG137 [64] phi (byte) findcol::i#12 = (byte) 0 -- xby=coby1 ldx #$0 + jmp b1 //SEG138 [64] phi from findcol::@13 to findcol::@1 - b1_from_b13: //SEG139 [64] phi (byte) findcol::mincol#11 = (byte) findcol::mincol#2 -- register_copy //SEG140 [64] phi (byte) findcol::mindiff#10 = (byte) findcol::mindiff#11 -- register_copy //SEG141 [64] phi (byte) findcol::i#12 = (byte) findcol::i#1 -- register_copy @@ -8384,7 +8392,6 @@ findcol: { sbc $7 sta $7 //SEG150 [70] phi from findcol::@7 to findcol::@8 - b8_from_b7: //SEG151 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#1 -- register_copy //SEG152 findcol::@8 b8: @@ -8402,7 +8409,6 @@ findcol: { clc adc $7 //SEG157 [74] phi from findcol::@10 to findcol::@11 - b11_from_b10: //SEG158 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#3 -- register_copy //SEG159 findcol::@11 b11: @@ -8410,7 +8416,6 @@ findcol: { cmp $6 bcc b12 //SEG161 [76] phi from findcol::@11 to findcol::@13 - b13_from_b11: //SEG162 [76] phi (byte) findcol::mindiff#11 = (byte) findcol::mindiff#10 -- register_copy //SEG163 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#11 -- register_copy //SEG164 findcol::@13 @@ -8419,7 +8424,7 @@ findcol: { inx //SEG166 [78] if((byte) findcol::i#1<(byte) numpoints#1) goto findcol::@1 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby_lt_zpby1_then_la1 cpx $8 - bcc b1_from_b13 + bcc b1 //SEG167 [79] phi from findcol::@13 to findcol::@return breturn_from_b13: //SEG168 [79] phi (byte) findcol::return#0 = (byte) findcol::mincol#2 -- register_copy @@ -8484,8 +8489,8 @@ initscreen: { sta $3 lda #>$400 sta $3+$1 + jmp b1 //SEG193 [87] phi from initscreen::@1 to initscreen::@1 - b1_from_b1: //SEG194 [87] phi (byte*) initscreen::screen#2 = (byte*) initscreen::screen#1 -- register_copy //SEG195 initscreen::@1 b1: @@ -8501,11 +8506,11 @@ initscreen: { //SEG198 [90] if((byte*) initscreen::screen#1<(word) 2024) goto initscreen::@1 [ initscreen::screen#1 ] -- zpptrby1_lt_cowo1_then_la1 lda $3+$1 cmp #>$7e8 - bcc b1_from_b1 + bcc b1 bne !+ lda $3 cmp #<$7e8 - bcc b1_from_b1 + bcc b1 !: //SEG199 initscreen::@return breturn: @@ -8533,6 +8538,964 @@ addpoint: { rts } +Removing instruction bbegin: +Removing instruction bend: +Removing instruction addpoint_from_main: +Removing instruction b3: +Removing instruction b4: +Removing instruction b5: +Removing instruction b6: +Removing instruction b7: +Removing instruction b8: +Removing instruction b10: +Removing instruction b11: +Removing instruction breturn: +Removing instruction b1_from_render: +Removing instruction b5: +Removing instruction b3: +Removing instruction breturn: +Removing instruction b1_from_findcol: +Removing instruction b7: +Removing instruction b10: +Removing instruction breturn_from_b13: +Removing instruction b13_from_b12: +Removing instruction b11_from_b9: +Removing instruction b8_from_b6: +Removing instruction b1_from_initscreen: +Removing instruction breturn: +Removing instruction breturn: +Succesful ASM optimization Pass6UnusedLabelElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call addpoint param-assignment [ ] + //SEG5 [92] phi from main to addpoint + //SEG6 [92] phi (byte) addpoint::c#6 = (byte) 1 -- zpby1=coby1 + lda #$1 + sta $2 + //SEG7 [92] phi (byte) addpoint::y#6 = (byte) 5 -- yby=coby1 + ldy #$5 + //SEG8 [92] phi (byte) numpoints#19 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $8 + //SEG9 [92] phi (byte) addpoint::x#6 = (byte) 5 -- aby=coby1 + lda #$5 + jsr addpoint + //SEG10 main::@3 + //SEG11 [2] call addpoint param-assignment [ ] + //SEG12 [92] phi from main::@3 to addpoint + //SEG13 [92] phi (byte) addpoint::c#6 = (byte) 2 -- zpby1=coby1 + lda #$2 + sta $2 + //SEG14 [92] phi (byte) addpoint::y#6 = (byte) 8 -- yby=coby1 + ldy #$8 + //SEG15 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG16 [92] phi (byte) addpoint::x#6 = (byte) 15 -- aby=coby1 + lda #$f + jsr addpoint + //SEG17 main::@4 + //SEG18 [3] call addpoint param-assignment [ ] + //SEG19 [92] phi from main::@4 to addpoint + //SEG20 [92] phi (byte) addpoint::c#6 = (byte) 3 -- zpby1=coby1 + lda #$3 + sta $2 + //SEG21 [92] phi (byte) addpoint::y#6 = (byte) 14 -- yby=coby1 + ldy #$e + //SEG22 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG23 [92] phi (byte) addpoint::x#6 = (byte) 6 -- aby=coby1 + lda #$6 + jsr addpoint + //SEG24 main::@5 + //SEG25 [4] call addpoint param-assignment [ ] + //SEG26 [92] phi from main::@5 to addpoint + //SEG27 [92] phi (byte) addpoint::c#6 = (byte) 4 -- zpby1=coby1 + lda #$4 + sta $2 + //SEG28 [92] phi (byte) addpoint::y#6 = (byte) 2 -- yby=coby1 + ldy #$2 + //SEG29 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG30 [92] phi (byte) addpoint::x#6 = (byte) 34 -- aby=coby1 + lda #$22 + jsr addpoint + //SEG31 main::@6 + //SEG32 [5] call addpoint param-assignment [ ] + //SEG33 [92] phi from main::@6 to addpoint + //SEG34 [92] phi (byte) addpoint::c#6 = (byte) 5 -- zpby1=coby1 + lda #$5 + sta $2 + //SEG35 [92] phi (byte) addpoint::y#6 = (byte) 17 -- yby=coby1 + ldy #$11 + //SEG36 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG37 [92] phi (byte) addpoint::x#6 = (byte) 21 -- aby=coby1 + lda #$15 + jsr addpoint + //SEG38 main::@7 + //SEG39 [6] call addpoint param-assignment [ ] + //SEG40 [92] phi from main::@7 to addpoint + //SEG41 [92] phi (byte) addpoint::c#6 = (byte) 7 -- zpby1=coby1 + lda #$7 + sta $2 + //SEG42 [92] phi (byte) addpoint::y#6 = (byte) 22 -- yby=coby1 + ldy #$16 + //SEG43 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG44 [92] phi (byte) addpoint::x#6 = (byte) 31 -- aby=coby1 + lda #$1f + jsr addpoint + //SEG45 main::@8 + //SEG46 [7] call initscreen param-assignment [ ] + jsr initscreen + //SEG47 main::@1 + b1: + //SEG48 [8] call render param-assignment [ ] + jsr render + //SEG49 main::@10 + //SEG50 [9] call animate param-assignment [ ] + jsr animate + //SEG51 main::@11 + //SEG52 [10] if(true) goto main::@1 [ ] -- true_then_la1 + jmp b1 + //SEG53 main::@return + //SEG54 [11] return [ ] + rts +} +//SEG55 animate +animate: { + //SEG56 [12] (byte~) animate::$0 ← * (word) 4096 [ animate::$0 ] -- aby=_star_cowo1 + lda $1000 + //SEG57 [13] (byte~) animate::$1 ← (byte~) animate::$0 + (byte) 1 [ animate::$1 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG58 [14] *((word) 4096) ← (byte~) animate::$1 [ ] -- _star_cowo1=aby + sta $1000 + //SEG59 [15] (byte~) animate::$2 ← * (word) 4096 [ animate::$2 ] -- aby=_star_cowo1 + lda $1000 + //SEG60 [16] if((byte~) animate::$2==(byte) 40) goto animate::@1 [ ] -- aby_eq_coby1_then_la1 + cmp #$28 + beq b1 + //SEG61 animate::@2 + b2: + //SEG62 [17] (byte~) animate::$4 ← * (word) 4352 [ animate::$4 ] -- aby=_star_cowo1 + lda $1100 + //SEG63 [18] (byte~) animate::$5 ← (byte~) animate::$4 + (byte) 1 [ animate::$5 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG64 [19] *((word) 4352) ← (byte~) animate::$5 [ ] -- _star_cowo1=aby + sta $1100 + //SEG65 [20] (byte~) animate::$6 ← * (word) 4352 [ animate::$6 ] -- aby=_star_cowo1 + lda $1100 + //SEG66 [21] if((byte~) animate::$6==(byte) 25) goto animate::@3 [ ] -- aby_eq_coby1_then_la1 + cmp #$19 + beq b3 + //SEG67 animate::@4 + b4: + //SEG68 [22] (byte~) animate::$8 ← * (word) 4097 [ animate::$8 ] -- xby=_star_cowo1 + ldx $1001 + //SEG69 [23] (byte~) animate::$9 ← (byte~) animate::$8 - (byte) 1 [ animate::$9 ] -- xby=xby_minus_1 + dex + //SEG70 [24] *((word) 4097) ← (byte~) animate::$9 [ ] -- _star_cowo1=xby + stx $1001 + //SEG71 [25] (byte~) animate::$10 ← * (word) 4097 [ animate::$10 ] -- aby=_star_cowo1 + lda $1001 + //SEG72 [26] if((byte~) animate::$10==(byte) 255) goto animate::@5 [ ] -- aby_eq_coby1_then_la1 + cmp #$ff + beq b5 + //SEG73 animate::@6 + b6: + //SEG74 [27] (byte~) animate::$12 ← * (word) 4354 [ animate::$12 ] -- aby=_star_cowo1 + lda $1102 + //SEG75 [28] (byte~) animate::$13 ← (byte~) animate::$12 + (byte) 1 [ animate::$13 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG76 [29] *((word) 4354) ← (byte~) animate::$13 [ ] -- _star_cowo1=aby + sta $1102 + //SEG77 [30] (byte~) animate::$14 ← * (word) 4354 [ animate::$14 ] -- aby=_star_cowo1 + lda $1102 + //SEG78 [31] if((byte~) animate::$14==(byte) 25) goto animate::@7 [ ] -- aby_eq_coby1_then_la1 + cmp #$19 + beq b7 + //SEG79 animate::@8 + b8: + //SEG80 [32] (byte~) animate::$16 ← * (word) 4355 [ animate::$16 ] -- xby=_star_cowo1 + ldx $1103 + //SEG81 [33] (byte~) animate::$17 ← (byte~) animate::$16 - (byte) 1 [ animate::$17 ] -- xby=xby_minus_1 + dex + //SEG82 [34] *((word) 4355) ← (byte~) animate::$17 [ ] -- _star_cowo1=xby + stx $1103 + //SEG83 [35] (byte~) animate::$18 ← * (word) 4355 [ animate::$18 ] -- aby=_star_cowo1 + lda $1103 + //SEG84 [36] if((byte~) animate::$18==(byte) 255) goto animate::@9 [ ] -- aby_eq_coby1_then_la1 + cmp #$ff + beq b9 + //SEG85 animate::@return + breturn: + //SEG86 [37] return [ ] + rts + //SEG87 animate::@9 + b9: + //SEG88 [38] *((word) 4355) ← (byte) 25 [ ] -- _star_cowo1=coby2 + lda #$19 + sta $1103 + //SEG89 [39] (byte~) animate::$20 ← * (word) 4099 [ animate::$20 ] -- aby=_star_cowo1 + lda $1003 + //SEG90 [40] (byte~) animate::$21 ← (byte~) animate::$20 + (byte) 7 [ animate::$21 ] -- aby=aby_plus_coby1 + clc + adc #$7 + //SEG91 [41] *((word) 4099) ← (byte~) animate::$21 [ ] -- _star_cowo1=aby + sta $1003 + //SEG92 [42] (byte~) animate::$22 ← * (word) 4099 [ animate::$22 ] -- aby=_star_cowo1 + lda $1003 + //SEG93 [43] if((byte~) animate::$22>=(byte) 40) goto animate::@11 [ ] -- aby_ge_coby1_then_la1 + cmp #$28 + bcs b11 + jmp breturn + //SEG94 animate::@11 + b11: + //SEG95 [44] (byte~) animate::$24 ← * (word) 4099 [ animate::$24 ] -- aby=_star_cowo1 + lda $1003 + //SEG96 [45] (byte~) animate::$25 ← (byte~) animate::$24 - (byte) 40 [ animate::$25 ] -- aby=aby_minus_coby1 + sec + sbc #$28 + //SEG97 [46] *((word) 4099) ← (byte~) animate::$25 [ ] -- _star_cowo1=aby + sta $1003 + jmp breturn + //SEG98 animate::@7 + b7: + //SEG99 [47] *((word) 4354) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1102 + jmp b8 + //SEG100 animate::@5 + b5: + //SEG101 [48] *((word) 4097) ← (byte) 40 [ ] -- _star_cowo1=coby2 + lda #$28 + sta $1001 + jmp b6 + //SEG102 animate::@3 + b3: + //SEG103 [49] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1100 + jmp b4 + //SEG104 animate::@1 + b1: + //SEG105 [50] *((word) 4096) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1000 + jmp b2 +} +//SEG106 render +render: { + //SEG107 [51] phi from render to render::@1 + //SEG108 [51] phi (byte*) render::colline#2 = (word) 55296 -- zpptrby1=cowo1 + lda #<$d800 + sta $3 + lda #>$d800 + sta $3+$1 + //SEG109 [51] phi (byte) render::y#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $2 + jmp b1 + //SEG110 [51] phi from render::@3 to render::@1 + //SEG111 [51] phi (byte*) render::colline#2 = (byte*) render::colline#1 -- register_copy + //SEG112 [51] phi (byte) render::y#2 = (byte) render::y#1 -- register_copy + //SEG113 render::@1 + b1: + //SEG114 [52] phi from render::@1 to render::@2 + //SEG115 [52] phi (byte) render::x#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $5 + jmp b2 + //SEG116 [52] phi from render::@5 to render::@2 + //SEG117 [52] phi (byte) render::x#2 = (byte) render::x#1 -- register_copy + //SEG118 render::@2 + b2: + //SEG119 [53] (byte) findcol::x#0 ← (byte) render::x#2 [ render::x#2 render::y#2 render::colline#2 ] -- zpby1=zpby2 + lda $5 + sta $9 + //SEG120 [54] (byte) findcol::y#0 ← (byte) render::y#2 [ render::x#2 render::y#2 render::colline#2 ] -- zpby1=zpby2 + lda $2 + sta $a + //SEG121 [55] call findcol param-assignment [ render::x#2 render::y#2 findcol::return#0 render::colline#2 ] + jsr findcol + //SEG122 render::@5 + //SEG123 [56] (byte) render::col#0 ← (byte) findcol::return#0 [ render::x#2 render::y#2 render::colline#2 render::col#0 ] -- aby=yby + tya + //SEG124 [57] *((byte*) render::colline#2 + (byte) render::x#2) ← (byte) render::col#0 [ render::x#2 render::y#2 render::colline#2 ] -- zpptrby1_staridx_zpby1=aby + ldy $5 + sta ($3),y + //SEG125 [58] (byte) render::x#1 ← ++ (byte) render::x#2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1=_inc_zpby1 + inc $5 + //SEG126 [59] if((byte) render::x#1<(byte) 40) goto render::@2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1_lt_coby1_then_la1 + lda $5 + cmp #$28 + bcc b2 + //SEG127 render::@3 + //SEG128 [60] (byte*) render::colline#1 ← (byte*) render::colline#2 + (byte) 40 [ render::colline#1 render::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $3 + clc + adc #$28 + sta $3 + bcc !+ + inc $3+$1 + !: + //SEG129 [61] (byte) render::y#1 ← ++ (byte) render::y#2 [ render::y#1 render::colline#1 ] -- zpby1=_inc_zpby1 + inc $2 + //SEG130 [62] if((byte) render::y#1<(byte) 25) goto render::@1 [ render::y#1 render::colline#1 ] -- zpby1_lt_coby1_then_la1 + lda $2 + cmp #$19 + bcc b1 + //SEG131 render::@return + //SEG132 [63] return [ ] + rts +} +//SEG133 findcol +findcol: { + //SEG134 [64] phi from findcol to findcol::@1 + //SEG135 [64] phi (byte) findcol::mincol#11 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG136 [64] phi (byte) findcol::mindiff#10 = (byte) 255 -- zpby1=coby1 + lda #$ff + sta $6 + //SEG137 [64] phi (byte) findcol::i#12 = (byte) 0 -- xby=coby1 + ldx #$0 + jmp b1 + //SEG138 [64] phi from findcol::@13 to findcol::@1 + //SEG139 [64] phi (byte) findcol::mincol#11 = (byte) findcol::mincol#2 -- register_copy + //SEG140 [64] phi (byte) findcol::mindiff#10 = (byte) findcol::mindiff#11 -- register_copy + //SEG141 [64] phi (byte) findcol::i#12 = (byte) findcol::i#1 -- register_copy + //SEG142 findcol::@1 + b1: + //SEG143 [65] (byte) findcol::xp#0 ← (word) 4096 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=cowo1_staridx_xby + lda $1000,x + sta $7 + //SEG144 [66] (byte) findcol::yp#0 ← (word) 4352 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=cowo1_staridx_xby + lda $1100,x + sta $b + //SEG145 [67] if((byte) findcol::x#0==(byte) findcol::xp#0) goto findcol::@2 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_eq_zpby2_then_la1 + lda $9 + cmp $7 + beq b2 + //SEG146 findcol::@3 + b3: + //SEG147 [68] if((byte) findcol::x#0<(byte) findcol::xp#0) goto findcol::@6 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_lt_zpby2_then_la1 + lda $9 + cmp $7 + bcc b6 + //SEG148 findcol::@7 + //SEG149 [69] (byte) findcol::diff#1 ← (byte) findcol::x#0 - (byte) findcol::xp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::diff#1 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=zpby2_minus_zpby1 + lda $9 + sec + sbc $7 + sta $7 + //SEG150 [70] phi from findcol::@7 to findcol::@8 + //SEG151 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#1 -- register_copy + //SEG152 findcol::@8 + b8: + //SEG153 [71] if((byte) findcol::y#0<(byte) findcol::yp#0) goto findcol::@9 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::yp#0 findcol::diff#4 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_lt_zpby2_then_la1 + lda $a + cmp $b + bcc b9 + //SEG154 findcol::@10 + //SEG155 [72] (byte~) findcol::$10 ← (byte) findcol::y#0 - (byte) findcol::yp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#4 findcol::$10 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_minus_zpby2 + lda $a + sec + sbc $b + //SEG156 [73] (byte) findcol::diff#3 ← (byte) findcol::diff#4 + (byte~) findcol::$10 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#3 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_plus_aby + clc + adc $7 + //SEG157 [74] phi from findcol::@10 to findcol::@11 + //SEG158 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#3 -- register_copy + //SEG159 findcol::@11 + b11: + //SEG160 [75] if((byte) findcol::diff#6<(byte) findcol::mindiff#10) goto findcol::@12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#6 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby_lt_zpby1_then_la1 + cmp $6 + bcc b12 + //SEG161 [76] phi from findcol::@11 to findcol::@13 + //SEG162 [76] phi (byte) findcol::mindiff#11 = (byte) findcol::mindiff#10 -- register_copy + //SEG163 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#11 -- register_copy + //SEG164 findcol::@13 + b13: + //SEG165 [77] (byte) findcol::i#1 ← ++ (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby=_inc_xby + inx + //SEG166 [78] if((byte) findcol::i#1<(byte) numpoints#1) goto findcol::@1 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby_lt_zpby1_then_la1 + cpx $8 + bcc b1 + //SEG167 [79] phi from findcol::@13 to findcol::@return + //SEG168 [79] phi (byte) findcol::return#0 = (byte) findcol::mincol#2 -- register_copy + jmp breturn + //SEG169 [79] phi from findcol::@2 to findcol::@return + breturn_from_b2: + //SEG170 [79] phi (byte) findcol::return#0 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG171 findcol::@return + breturn: + //SEG172 [80] return [ render::x#2 render::y#2 findcol::return#0 render::colline#2 ] + rts + //SEG173 findcol::@12 + b12: + //SEG174 [81] (byte) findcol::mincol#1 ← (word) 4608 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#6 findcol::mincol#1 numpoints#1 ] -- yby=cowo1_staridx_xby + ldy $1200,x + //SEG175 [82] (byte~) findcol::diff#13 ← (byte) findcol::diff#6 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::mincol#1 findcol::diff#13 numpoints#1 ] -- zpby1=aby + sta $6 + //SEG176 [76] phi from findcol::@12 to findcol::@13 + //SEG177 [76] phi (byte) findcol::mindiff#11 = (byte~) findcol::diff#13 -- register_copy + //SEG178 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#1 -- register_copy + jmp b13 + //SEG179 findcol::@9 + b9: + //SEG180 [83] (byte~) findcol::$8 ← (byte) findcol::yp#0 - (byte) findcol::y#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#4 findcol::mindiff#10 findcol::mincol#11 numpoints#1 findcol::$8 ] -- aby=zpby1_minus_zpby2 + lda $b + sec + sbc $a + //SEG181 [84] (byte) findcol::diff#2 ← (byte) findcol::diff#4 + (byte~) findcol::$8 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#2 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_plus_aby + clc + adc $7 + //SEG182 [74] phi from findcol::@9 to findcol::@11 + //SEG183 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#2 -- register_copy + jmp b11 + //SEG184 findcol::@6 + b6: + //SEG185 [85] (byte) findcol::diff#0 ← (byte) findcol::xp#0 - (byte) findcol::x#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::diff#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=zpby1_minus_zpby2 + lda $7 + sec + sbc $9 + sta $7 + //SEG186 [70] phi from findcol::@6 to findcol::@8 + //SEG187 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#0 -- register_copy + jmp b8 + //SEG188 findcol::@2 + b2: + //SEG189 [86] if((byte) findcol::y#0==(byte) findcol::yp#0) goto findcol::@return [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_eq_zpby2_then_la1 + lda $a + cmp $b + beq breturn_from_b2 + jmp b3 +} +//SEG190 initscreen +initscreen: { + //SEG191 [87] phi from initscreen to initscreen::@1 + //SEG192 [87] phi (byte*) initscreen::screen#2 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $3 + lda #>$400 + sta $3+$1 + jmp b1 + //SEG193 [87] phi from initscreen::@1 to initscreen::@1 + //SEG194 [87] phi (byte*) initscreen::screen#2 = (byte*) initscreen::screen#1 -- register_copy + //SEG195 initscreen::@1 + b1: + //SEG196 [88] *((byte*) initscreen::screen#2) ← (byte) 230 [ initscreen::screen#2 ] -- _star_zpptrby1=coby1 + ldy #$0 + lda #$e6 + sta ($3),y + //SEG197 [89] (byte*) initscreen::screen#1 ← ++ (byte*) initscreen::screen#2 [ initscreen::screen#1 ] -- zpptrby1=_inc_zpptrby1 + inc $3 + bne !+ + inc $3+$1 + !: + //SEG198 [90] if((byte*) initscreen::screen#1<(word) 2024) goto initscreen::@1 [ initscreen::screen#1 ] -- zpptrby1_lt_cowo1_then_la1 + lda $3+$1 + cmp #>$7e8 + bcc b1 + bne !+ + lda $3 + cmp #<$7e8 + bcc b1 + !: + //SEG199 initscreen::@return + //SEG200 [91] return [ ] + rts +} +//SEG201 addpoint +addpoint: { + //SEG202 [93] *((word) 4096 + (byte) numpoints#19) ← (byte) addpoint::x#6 [ numpoints#19 addpoint::y#6 addpoint::c#6 ] -- cowo1_staridx_zpby1=aby + ldx $8 + sta $1000,x + //SEG203 [94] *((word) 4352 + (byte) numpoints#19) ← (byte) addpoint::y#6 [ numpoints#19 addpoint::c#6 ] -- cowo1_staridx_zpby1=yby + tya + ldy $8 + sta $1100,y + //SEG204 [95] *((word) 4608 + (byte) numpoints#19) ← (byte) addpoint::c#6 [ numpoints#19 ] -- cowo1_staridx_zpby1=zpby2 + lda $2 + ldx $8 + sta $1200,x + //SEG205 [96] (byte) numpoints#1 ← ++ (byte) numpoints#19 [ ] -- zpby1=_inc_zpby1 + inc $8 + //SEG206 addpoint::@return + //SEG207 [97] return [ ] + rts +} + +Removing instruction jmp b1 +Removing instruction jmp b2 +Removing instruction jmp b1 +Removing instruction jmp b1 +Succesful ASM optimization Pass6NextJumpElimination +ASSEMBLER +//SEG0 @begin +//SEG1 [0] call main param-assignment [ ] + jsr main +//SEG2 @end +//SEG3 main +main: { + //SEG4 [1] call addpoint param-assignment [ ] + //SEG5 [92] phi from main to addpoint + //SEG6 [92] phi (byte) addpoint::c#6 = (byte) 1 -- zpby1=coby1 + lda #$1 + sta $2 + //SEG7 [92] phi (byte) addpoint::y#6 = (byte) 5 -- yby=coby1 + ldy #$5 + //SEG8 [92] phi (byte) numpoints#19 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $8 + //SEG9 [92] phi (byte) addpoint::x#6 = (byte) 5 -- aby=coby1 + lda #$5 + jsr addpoint + //SEG10 main::@3 + //SEG11 [2] call addpoint param-assignment [ ] + //SEG12 [92] phi from main::@3 to addpoint + //SEG13 [92] phi (byte) addpoint::c#6 = (byte) 2 -- zpby1=coby1 + lda #$2 + sta $2 + //SEG14 [92] phi (byte) addpoint::y#6 = (byte) 8 -- yby=coby1 + ldy #$8 + //SEG15 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG16 [92] phi (byte) addpoint::x#6 = (byte) 15 -- aby=coby1 + lda #$f + jsr addpoint + //SEG17 main::@4 + //SEG18 [3] call addpoint param-assignment [ ] + //SEG19 [92] phi from main::@4 to addpoint + //SEG20 [92] phi (byte) addpoint::c#6 = (byte) 3 -- zpby1=coby1 + lda #$3 + sta $2 + //SEG21 [92] phi (byte) addpoint::y#6 = (byte) 14 -- yby=coby1 + ldy #$e + //SEG22 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG23 [92] phi (byte) addpoint::x#6 = (byte) 6 -- aby=coby1 + lda #$6 + jsr addpoint + //SEG24 main::@5 + //SEG25 [4] call addpoint param-assignment [ ] + //SEG26 [92] phi from main::@5 to addpoint + //SEG27 [92] phi (byte) addpoint::c#6 = (byte) 4 -- zpby1=coby1 + lda #$4 + sta $2 + //SEG28 [92] phi (byte) addpoint::y#6 = (byte) 2 -- yby=coby1 + ldy #$2 + //SEG29 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG30 [92] phi (byte) addpoint::x#6 = (byte) 34 -- aby=coby1 + lda #$22 + jsr addpoint + //SEG31 main::@6 + //SEG32 [5] call addpoint param-assignment [ ] + //SEG33 [92] phi from main::@6 to addpoint + //SEG34 [92] phi (byte) addpoint::c#6 = (byte) 5 -- zpby1=coby1 + lda #$5 + sta $2 + //SEG35 [92] phi (byte) addpoint::y#6 = (byte) 17 -- yby=coby1 + ldy #$11 + //SEG36 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG37 [92] phi (byte) addpoint::x#6 = (byte) 21 -- aby=coby1 + lda #$15 + jsr addpoint + //SEG38 main::@7 + //SEG39 [6] call addpoint param-assignment [ ] + //SEG40 [92] phi from main::@7 to addpoint + //SEG41 [92] phi (byte) addpoint::c#6 = (byte) 7 -- zpby1=coby1 + lda #$7 + sta $2 + //SEG42 [92] phi (byte) addpoint::y#6 = (byte) 22 -- yby=coby1 + ldy #$16 + //SEG43 [92] phi (byte) numpoints#19 = (byte) numpoints#1 -- register_copy + //SEG44 [92] phi (byte) addpoint::x#6 = (byte) 31 -- aby=coby1 + lda #$1f + jsr addpoint + //SEG45 main::@8 + //SEG46 [7] call initscreen param-assignment [ ] + jsr initscreen + //SEG47 main::@1 + b1: + //SEG48 [8] call render param-assignment [ ] + jsr render + //SEG49 main::@10 + //SEG50 [9] call animate param-assignment [ ] + jsr animate + //SEG51 main::@11 + //SEG52 [10] if(true) goto main::@1 [ ] -- true_then_la1 + jmp b1 + //SEG53 main::@return + //SEG54 [11] return [ ] + rts +} +//SEG55 animate +animate: { + //SEG56 [12] (byte~) animate::$0 ← * (word) 4096 [ animate::$0 ] -- aby=_star_cowo1 + lda $1000 + //SEG57 [13] (byte~) animate::$1 ← (byte~) animate::$0 + (byte) 1 [ animate::$1 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG58 [14] *((word) 4096) ← (byte~) animate::$1 [ ] -- _star_cowo1=aby + sta $1000 + //SEG59 [15] (byte~) animate::$2 ← * (word) 4096 [ animate::$2 ] -- aby=_star_cowo1 + lda $1000 + //SEG60 [16] if((byte~) animate::$2==(byte) 40) goto animate::@1 [ ] -- aby_eq_coby1_then_la1 + cmp #$28 + beq b1 + //SEG61 animate::@2 + b2: + //SEG62 [17] (byte~) animate::$4 ← * (word) 4352 [ animate::$4 ] -- aby=_star_cowo1 + lda $1100 + //SEG63 [18] (byte~) animate::$5 ← (byte~) animate::$4 + (byte) 1 [ animate::$5 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG64 [19] *((word) 4352) ← (byte~) animate::$5 [ ] -- _star_cowo1=aby + sta $1100 + //SEG65 [20] (byte~) animate::$6 ← * (word) 4352 [ animate::$6 ] -- aby=_star_cowo1 + lda $1100 + //SEG66 [21] if((byte~) animate::$6==(byte) 25) goto animate::@3 [ ] -- aby_eq_coby1_then_la1 + cmp #$19 + beq b3 + //SEG67 animate::@4 + b4: + //SEG68 [22] (byte~) animate::$8 ← * (word) 4097 [ animate::$8 ] -- xby=_star_cowo1 + ldx $1001 + //SEG69 [23] (byte~) animate::$9 ← (byte~) animate::$8 - (byte) 1 [ animate::$9 ] -- xby=xby_minus_1 + dex + //SEG70 [24] *((word) 4097) ← (byte~) animate::$9 [ ] -- _star_cowo1=xby + stx $1001 + //SEG71 [25] (byte~) animate::$10 ← * (word) 4097 [ animate::$10 ] -- aby=_star_cowo1 + lda $1001 + //SEG72 [26] if((byte~) animate::$10==(byte) 255) goto animate::@5 [ ] -- aby_eq_coby1_then_la1 + cmp #$ff + beq b5 + //SEG73 animate::@6 + b6: + //SEG74 [27] (byte~) animate::$12 ← * (word) 4354 [ animate::$12 ] -- aby=_star_cowo1 + lda $1102 + //SEG75 [28] (byte~) animate::$13 ← (byte~) animate::$12 + (byte) 1 [ animate::$13 ] -- aby=aby_plus_1 + clc + adc #$1 + //SEG76 [29] *((word) 4354) ← (byte~) animate::$13 [ ] -- _star_cowo1=aby + sta $1102 + //SEG77 [30] (byte~) animate::$14 ← * (word) 4354 [ animate::$14 ] -- aby=_star_cowo1 + lda $1102 + //SEG78 [31] if((byte~) animate::$14==(byte) 25) goto animate::@7 [ ] -- aby_eq_coby1_then_la1 + cmp #$19 + beq b7 + //SEG79 animate::@8 + b8: + //SEG80 [32] (byte~) animate::$16 ← * (word) 4355 [ animate::$16 ] -- xby=_star_cowo1 + ldx $1103 + //SEG81 [33] (byte~) animate::$17 ← (byte~) animate::$16 - (byte) 1 [ animate::$17 ] -- xby=xby_minus_1 + dex + //SEG82 [34] *((word) 4355) ← (byte~) animate::$17 [ ] -- _star_cowo1=xby + stx $1103 + //SEG83 [35] (byte~) animate::$18 ← * (word) 4355 [ animate::$18 ] -- aby=_star_cowo1 + lda $1103 + //SEG84 [36] if((byte~) animate::$18==(byte) 255) goto animate::@9 [ ] -- aby_eq_coby1_then_la1 + cmp #$ff + beq b9 + //SEG85 animate::@return + breturn: + //SEG86 [37] return [ ] + rts + //SEG87 animate::@9 + b9: + //SEG88 [38] *((word) 4355) ← (byte) 25 [ ] -- _star_cowo1=coby2 + lda #$19 + sta $1103 + //SEG89 [39] (byte~) animate::$20 ← * (word) 4099 [ animate::$20 ] -- aby=_star_cowo1 + lda $1003 + //SEG90 [40] (byte~) animate::$21 ← (byte~) animate::$20 + (byte) 7 [ animate::$21 ] -- aby=aby_plus_coby1 + clc + adc #$7 + //SEG91 [41] *((word) 4099) ← (byte~) animate::$21 [ ] -- _star_cowo1=aby + sta $1003 + //SEG92 [42] (byte~) animate::$22 ← * (word) 4099 [ animate::$22 ] -- aby=_star_cowo1 + lda $1003 + //SEG93 [43] if((byte~) animate::$22>=(byte) 40) goto animate::@11 [ ] -- aby_ge_coby1_then_la1 + cmp #$28 + bcs b11 + jmp breturn + //SEG94 animate::@11 + b11: + //SEG95 [44] (byte~) animate::$24 ← * (word) 4099 [ animate::$24 ] -- aby=_star_cowo1 + lda $1003 + //SEG96 [45] (byte~) animate::$25 ← (byte~) animate::$24 - (byte) 40 [ animate::$25 ] -- aby=aby_minus_coby1 + sec + sbc #$28 + //SEG97 [46] *((word) 4099) ← (byte~) animate::$25 [ ] -- _star_cowo1=aby + sta $1003 + jmp breturn + //SEG98 animate::@7 + b7: + //SEG99 [47] *((word) 4354) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1102 + jmp b8 + //SEG100 animate::@5 + b5: + //SEG101 [48] *((word) 4097) ← (byte) 40 [ ] -- _star_cowo1=coby2 + lda #$28 + sta $1001 + jmp b6 + //SEG102 animate::@3 + b3: + //SEG103 [49] *((word) 4352) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1100 + jmp b4 + //SEG104 animate::@1 + b1: + //SEG105 [50] *((word) 4096) ← (byte) 0 [ ] -- _star_cowo1=coby2 + lda #$0 + sta $1000 + jmp b2 +} +//SEG106 render +render: { + //SEG107 [51] phi from render to render::@1 + //SEG108 [51] phi (byte*) render::colline#2 = (word) 55296 -- zpptrby1=cowo1 + lda #<$d800 + sta $3 + lda #>$d800 + sta $3+$1 + //SEG109 [51] phi (byte) render::y#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $2 + //SEG110 [51] phi from render::@3 to render::@1 + //SEG111 [51] phi (byte*) render::colline#2 = (byte*) render::colline#1 -- register_copy + //SEG112 [51] phi (byte) render::y#2 = (byte) render::y#1 -- register_copy + //SEG113 render::@1 + b1: + //SEG114 [52] phi from render::@1 to render::@2 + //SEG115 [52] phi (byte) render::x#2 = (byte) 0 -- zpby1=coby1 + lda #$0 + sta $5 + //SEG116 [52] phi from render::@5 to render::@2 + //SEG117 [52] phi (byte) render::x#2 = (byte) render::x#1 -- register_copy + //SEG118 render::@2 + b2: + //SEG119 [53] (byte) findcol::x#0 ← (byte) render::x#2 [ render::x#2 render::y#2 render::colline#2 ] -- zpby1=zpby2 + lda $5 + sta $9 + //SEG120 [54] (byte) findcol::y#0 ← (byte) render::y#2 [ render::x#2 render::y#2 render::colline#2 ] -- zpby1=zpby2 + lda $2 + sta $a + //SEG121 [55] call findcol param-assignment [ render::x#2 render::y#2 findcol::return#0 render::colline#2 ] + jsr findcol + //SEG122 render::@5 + //SEG123 [56] (byte) render::col#0 ← (byte) findcol::return#0 [ render::x#2 render::y#2 render::colline#2 render::col#0 ] -- aby=yby + tya + //SEG124 [57] *((byte*) render::colline#2 + (byte) render::x#2) ← (byte) render::col#0 [ render::x#2 render::y#2 render::colline#2 ] -- zpptrby1_staridx_zpby1=aby + ldy $5 + sta ($3),y + //SEG125 [58] (byte) render::x#1 ← ++ (byte) render::x#2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1=_inc_zpby1 + inc $5 + //SEG126 [59] if((byte) render::x#1<(byte) 40) goto render::@2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1_lt_coby1_then_la1 + lda $5 + cmp #$28 + bcc b2 + //SEG127 render::@3 + //SEG128 [60] (byte*) render::colline#1 ← (byte*) render::colline#2 + (byte) 40 [ render::colline#1 render::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 + lda $3 + clc + adc #$28 + sta $3 + bcc !+ + inc $3+$1 + !: + //SEG129 [61] (byte) render::y#1 ← ++ (byte) render::y#2 [ render::y#1 render::colline#1 ] -- zpby1=_inc_zpby1 + inc $2 + //SEG130 [62] if((byte) render::y#1<(byte) 25) goto render::@1 [ render::y#1 render::colline#1 ] -- zpby1_lt_coby1_then_la1 + lda $2 + cmp #$19 + bcc b1 + //SEG131 render::@return + //SEG132 [63] return [ ] + rts +} +//SEG133 findcol +findcol: { + //SEG134 [64] phi from findcol to findcol::@1 + //SEG135 [64] phi (byte) findcol::mincol#11 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG136 [64] phi (byte) findcol::mindiff#10 = (byte) 255 -- zpby1=coby1 + lda #$ff + sta $6 + //SEG137 [64] phi (byte) findcol::i#12 = (byte) 0 -- xby=coby1 + ldx #$0 + //SEG138 [64] phi from findcol::@13 to findcol::@1 + //SEG139 [64] phi (byte) findcol::mincol#11 = (byte) findcol::mincol#2 -- register_copy + //SEG140 [64] phi (byte) findcol::mindiff#10 = (byte) findcol::mindiff#11 -- register_copy + //SEG141 [64] phi (byte) findcol::i#12 = (byte) findcol::i#1 -- register_copy + //SEG142 findcol::@1 + b1: + //SEG143 [65] (byte) findcol::xp#0 ← (word) 4096 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=cowo1_staridx_xby + lda $1000,x + sta $7 + //SEG144 [66] (byte) findcol::yp#0 ← (word) 4352 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=cowo1_staridx_xby + lda $1100,x + sta $b + //SEG145 [67] if((byte) findcol::x#0==(byte) findcol::xp#0) goto findcol::@2 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_eq_zpby2_then_la1 + lda $9 + cmp $7 + beq b2 + //SEG146 findcol::@3 + b3: + //SEG147 [68] if((byte) findcol::x#0<(byte) findcol::xp#0) goto findcol::@6 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_lt_zpby2_then_la1 + lda $9 + cmp $7 + bcc b6 + //SEG148 findcol::@7 + //SEG149 [69] (byte) findcol::diff#1 ← (byte) findcol::x#0 - (byte) findcol::xp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::diff#1 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=zpby2_minus_zpby1 + lda $9 + sec + sbc $7 + sta $7 + //SEG150 [70] phi from findcol::@7 to findcol::@8 + //SEG151 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#1 -- register_copy + //SEG152 findcol::@8 + b8: + //SEG153 [71] if((byte) findcol::y#0<(byte) findcol::yp#0) goto findcol::@9 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::yp#0 findcol::diff#4 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_lt_zpby2_then_la1 + lda $a + cmp $b + bcc b9 + //SEG154 findcol::@10 + //SEG155 [72] (byte~) findcol::$10 ← (byte) findcol::y#0 - (byte) findcol::yp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#4 findcol::$10 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_minus_zpby2 + lda $a + sec + sbc $b + //SEG156 [73] (byte) findcol::diff#3 ← (byte) findcol::diff#4 + (byte~) findcol::$10 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#3 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_plus_aby + clc + adc $7 + //SEG157 [74] phi from findcol::@10 to findcol::@11 + //SEG158 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#3 -- register_copy + //SEG159 findcol::@11 + b11: + //SEG160 [75] if((byte) findcol::diff#6<(byte) findcol::mindiff#10) goto findcol::@12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#6 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby_lt_zpby1_then_la1 + cmp $6 + bcc b12 + //SEG161 [76] phi from findcol::@11 to findcol::@13 + //SEG162 [76] phi (byte) findcol::mindiff#11 = (byte) findcol::mindiff#10 -- register_copy + //SEG163 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#11 -- register_copy + //SEG164 findcol::@13 + b13: + //SEG165 [77] (byte) findcol::i#1 ← ++ (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby=_inc_xby + inx + //SEG166 [78] if((byte) findcol::i#1<(byte) numpoints#1) goto findcol::@1 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby_lt_zpby1_then_la1 + cpx $8 + bcc b1 + //SEG167 [79] phi from findcol::@13 to findcol::@return + //SEG168 [79] phi (byte) findcol::return#0 = (byte) findcol::mincol#2 -- register_copy + jmp breturn + //SEG169 [79] phi from findcol::@2 to findcol::@return + breturn_from_b2: + //SEG170 [79] phi (byte) findcol::return#0 = (byte) 0 -- yby=coby1 + ldy #$0 + //SEG171 findcol::@return + breturn: + //SEG172 [80] return [ render::x#2 render::y#2 findcol::return#0 render::colline#2 ] + rts + //SEG173 findcol::@12 + b12: + //SEG174 [81] (byte) findcol::mincol#1 ← (word) 4608 *idx (byte) findcol::i#12 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#6 findcol::mincol#1 numpoints#1 ] -- yby=cowo1_staridx_xby + ldy $1200,x + //SEG175 [82] (byte~) findcol::diff#13 ← (byte) findcol::diff#6 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::mincol#1 findcol::diff#13 numpoints#1 ] -- zpby1=aby + sta $6 + //SEG176 [76] phi from findcol::@12 to findcol::@13 + //SEG177 [76] phi (byte) findcol::mindiff#11 = (byte~) findcol::diff#13 -- register_copy + //SEG178 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#1 -- register_copy + jmp b13 + //SEG179 findcol::@9 + b9: + //SEG180 [83] (byte~) findcol::$8 ← (byte) findcol::yp#0 - (byte) findcol::y#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#4 findcol::mindiff#10 findcol::mincol#11 numpoints#1 findcol::$8 ] -- aby=zpby1_minus_zpby2 + lda $b + sec + sbc $a + //SEG181 [84] (byte) findcol::diff#2 ← (byte) findcol::diff#4 + (byte~) findcol::$8 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#2 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_plus_aby + clc + adc $7 + //SEG182 [74] phi from findcol::@9 to findcol::@11 + //SEG183 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#2 -- register_copy + jmp b11 + //SEG184 findcol::@6 + b6: + //SEG185 [85] (byte) findcol::diff#0 ← (byte) findcol::xp#0 - (byte) findcol::x#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::diff#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=zpby1_minus_zpby2 + lda $7 + sec + sbc $9 + sta $7 + //SEG186 [70] phi from findcol::@6 to findcol::@8 + //SEG187 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#0 -- register_copy + jmp b8 + //SEG188 findcol::@2 + b2: + //SEG189 [86] if((byte) findcol::y#0==(byte) findcol::yp#0) goto findcol::@return [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::xp#0 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1_eq_zpby2_then_la1 + lda $a + cmp $b + beq breturn_from_b2 + jmp b3 +} +//SEG190 initscreen +initscreen: { + //SEG191 [87] phi from initscreen to initscreen::@1 + //SEG192 [87] phi (byte*) initscreen::screen#2 = (word) 1024 -- zpptrby1=cowo1 + lda #<$400 + sta $3 + lda #>$400 + sta $3+$1 + //SEG193 [87] phi from initscreen::@1 to initscreen::@1 + //SEG194 [87] phi (byte*) initscreen::screen#2 = (byte*) initscreen::screen#1 -- register_copy + //SEG195 initscreen::@1 + b1: + //SEG196 [88] *((byte*) initscreen::screen#2) ← (byte) 230 [ initscreen::screen#2 ] -- _star_zpptrby1=coby1 + ldy #$0 + lda #$e6 + sta ($3),y + //SEG197 [89] (byte*) initscreen::screen#1 ← ++ (byte*) initscreen::screen#2 [ initscreen::screen#1 ] -- zpptrby1=_inc_zpptrby1 + inc $3 + bne !+ + inc $3+$1 + !: + //SEG198 [90] if((byte*) initscreen::screen#1<(word) 2024) goto initscreen::@1 [ initscreen::screen#1 ] -- zpptrby1_lt_cowo1_then_la1 + lda $3+$1 + cmp #>$7e8 + bcc b1 + bne !+ + lda $3 + cmp #<$7e8 + bcc b1 + !: + //SEG199 initscreen::@return + //SEG200 [91] return [ ] + rts +} +//SEG201 addpoint +addpoint: { + //SEG202 [93] *((word) 4096 + (byte) numpoints#19) ← (byte) addpoint::x#6 [ numpoints#19 addpoint::y#6 addpoint::c#6 ] -- cowo1_staridx_zpby1=aby + ldx $8 + sta $1000,x + //SEG203 [94] *((word) 4352 + (byte) numpoints#19) ← (byte) addpoint::y#6 [ numpoints#19 addpoint::c#6 ] -- cowo1_staridx_zpby1=yby + tya + ldy $8 + sta $1100,y + //SEG204 [95] *((word) 4608 + (byte) numpoints#19) ← (byte) addpoint::c#6 [ numpoints#19 ] -- cowo1_staridx_zpby1=zpby2 + lda $2 + ldx $8 + sta $1200,x + //SEG205 [96] (byte) numpoints#1 ← ++ (byte) numpoints#19 [ ] -- zpby1=_inc_zpby1 + inc $8 + //SEG206 addpoint::@return + //SEG207 [97] return [ ] + rts +} + FINAL SYMBOL TABLE (label) @begin (label) @end @@ -8703,16 +9666,13 @@ reg byte a [ findcol::$8 ] FINAL CODE //SEG0 @begin -bbegin: //SEG1 [0] call main param-assignment [ ] jsr main //SEG2 @end -bend: //SEG3 main main: { //SEG4 [1] call addpoint param-assignment [ ] //SEG5 [92] phi from main to addpoint - addpoint_from_main: //SEG6 [92] phi (byte) addpoint::c#6 = (byte) 1 -- zpby1=coby1 lda #$1 sta $2 @@ -8725,10 +9685,8 @@ main: { lda #$5 jsr addpoint //SEG10 main::@3 - b3: //SEG11 [2] call addpoint param-assignment [ ] //SEG12 [92] phi from main::@3 to addpoint - addpoint_from_b3: //SEG13 [92] phi (byte) addpoint::c#6 = (byte) 2 -- zpby1=coby1 lda #$2 sta $2 @@ -8739,10 +9697,8 @@ main: { lda #$f jsr addpoint //SEG17 main::@4 - b4: //SEG18 [3] call addpoint param-assignment [ ] //SEG19 [92] phi from main::@4 to addpoint - addpoint_from_b4: //SEG20 [92] phi (byte) addpoint::c#6 = (byte) 3 -- zpby1=coby1 lda #$3 sta $2 @@ -8753,10 +9709,8 @@ main: { lda #$6 jsr addpoint //SEG24 main::@5 - b5: //SEG25 [4] call addpoint param-assignment [ ] //SEG26 [92] phi from main::@5 to addpoint - addpoint_from_b5: //SEG27 [92] phi (byte) addpoint::c#6 = (byte) 4 -- zpby1=coby1 lda #$4 sta $2 @@ -8767,10 +9721,8 @@ main: { lda #$22 jsr addpoint //SEG31 main::@6 - b6: //SEG32 [5] call addpoint param-assignment [ ] //SEG33 [92] phi from main::@6 to addpoint - addpoint_from_b6: //SEG34 [92] phi (byte) addpoint::c#6 = (byte) 5 -- zpby1=coby1 lda #$5 sta $2 @@ -8781,10 +9733,8 @@ main: { lda #$15 jsr addpoint //SEG38 main::@7 - b7: //SEG39 [6] call addpoint param-assignment [ ] //SEG40 [92] phi from main::@7 to addpoint - addpoint_from_b7: //SEG41 [92] phi (byte) addpoint::c#6 = (byte) 7 -- zpby1=coby1 lda #$7 sta $2 @@ -8795,7 +9745,6 @@ main: { lda #$1f jsr addpoint //SEG45 main::@8 - b8: //SEG46 [7] call initscreen param-assignment [ ] jsr initscreen //SEG47 main::@1 @@ -8803,15 +9752,12 @@ main: { //SEG48 [8] call render param-assignment [ ] jsr render //SEG49 main::@10 - b10: //SEG50 [9] call animate param-assignment [ ] jsr animate //SEG51 main::@11 - b11: //SEG52 [10] if(true) goto main::@1 [ ] -- true_then_la1 jmp b1 //SEG53 main::@return - breturn: //SEG54 [11] return [ ] rts } @@ -8943,7 +9889,6 @@ animate: { //SEG106 render render: { //SEG107 [51] phi from render to render::@1 - b1_from_render: //SEG108 [51] phi (byte*) render::colline#2 = (word) 55296 -- zpptrby1=cowo1 lda #<$d800 sta $3 @@ -8953,18 +9898,15 @@ render: { lda #$0 sta $2 //SEG110 [51] phi from render::@3 to render::@1 - b1_from_b3: //SEG111 [51] phi (byte*) render::colline#2 = (byte*) render::colline#1 -- register_copy //SEG112 [51] phi (byte) render::y#2 = (byte) render::y#1 -- register_copy //SEG113 render::@1 b1: //SEG114 [52] phi from render::@1 to render::@2 - b2_from_b1: //SEG115 [52] phi (byte) render::x#2 = (byte) 0 -- zpby1=coby1 lda #$0 sta $5 //SEG116 [52] phi from render::@5 to render::@2 - b2_from_b5: //SEG117 [52] phi (byte) render::x#2 = (byte) render::x#1 -- register_copy //SEG118 render::@2 b2: @@ -8977,7 +9919,6 @@ render: { //SEG121 [55] call findcol param-assignment [ render::x#2 render::y#2 findcol::return#0 render::colline#2 ] jsr findcol //SEG122 render::@5 - b5: //SEG123 [56] (byte) render::col#0 ← (byte) findcol::return#0 [ render::x#2 render::y#2 render::colline#2 render::col#0 ] -- aby=yby tya //SEG124 [57] *((byte*) render::colline#2 + (byte) render::x#2) ← (byte) render::col#0 [ render::x#2 render::y#2 render::colline#2 ] -- zpptrby1_staridx_zpby1=aby @@ -8988,9 +9929,8 @@ render: { //SEG126 [59] if((byte) render::x#1<(byte) 40) goto render::@2 [ render::x#1 render::y#2 render::colline#2 ] -- zpby1_lt_coby1_then_la1 lda $5 cmp #$28 - bcc b2_from_b5 + bcc b2 //SEG127 render::@3 - b3: //SEG128 [60] (byte*) render::colline#1 ← (byte*) render::colline#2 + (byte) 40 [ render::colline#1 render::y#2 ] -- zpptrby1=zpptrby1_plus_coby1 lda $3 clc @@ -9004,16 +9944,14 @@ render: { //SEG130 [62] if((byte) render::y#1<(byte) 25) goto render::@1 [ render::y#1 render::colline#1 ] -- zpby1_lt_coby1_then_la1 lda $2 cmp #$19 - bcc b1_from_b3 + bcc b1 //SEG131 render::@return - breturn: //SEG132 [63] return [ ] rts } //SEG133 findcol findcol: { //SEG134 [64] phi from findcol to findcol::@1 - b1_from_findcol: //SEG135 [64] phi (byte) findcol::mincol#11 = (byte) 0 -- yby=coby1 ldy #$0 //SEG136 [64] phi (byte) findcol::mindiff#10 = (byte) 255 -- zpby1=coby1 @@ -9022,7 +9960,6 @@ findcol: { //SEG137 [64] phi (byte) findcol::i#12 = (byte) 0 -- xby=coby1 ldx #$0 //SEG138 [64] phi from findcol::@13 to findcol::@1 - b1_from_b13: //SEG139 [64] phi (byte) findcol::mincol#11 = (byte) findcol::mincol#2 -- register_copy //SEG140 [64] phi (byte) findcol::mindiff#10 = (byte) findcol::mindiff#11 -- register_copy //SEG141 [64] phi (byte) findcol::i#12 = (byte) findcol::i#1 -- register_copy @@ -9045,14 +9982,12 @@ findcol: { cmp $7 bcc b6 //SEG148 findcol::@7 - b7: //SEG149 [69] (byte) findcol::diff#1 ← (byte) findcol::x#0 - (byte) findcol::xp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::diff#1 findcol::y#0 findcol::yp#0 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- zpby1=zpby2_minus_zpby1 lda $9 sec sbc $7 sta $7 //SEG150 [70] phi from findcol::@7 to findcol::@8 - b8_from_b7: //SEG151 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#1 -- register_copy //SEG152 findcol::@8 b8: @@ -9061,7 +9996,6 @@ findcol: { cmp $b bcc b9 //SEG154 findcol::@10 - b10: //SEG155 [72] (byte~) findcol::$10 ← (byte) findcol::y#0 - (byte) findcol::yp#0 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::diff#4 findcol::$10 findcol::mindiff#10 findcol::mincol#11 numpoints#1 ] -- aby=zpby1_minus_zpby2 lda $a sec @@ -9070,7 +10004,6 @@ findcol: { clc adc $7 //SEG157 [74] phi from findcol::@10 to findcol::@11 - b11_from_b10: //SEG158 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#3 -- register_copy //SEG159 findcol::@11 b11: @@ -9078,7 +10011,6 @@ findcol: { cmp $6 bcc b12 //SEG161 [76] phi from findcol::@11 to findcol::@13 - b13_from_b11: //SEG162 [76] phi (byte) findcol::mindiff#11 = (byte) findcol::mindiff#10 -- register_copy //SEG163 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#11 -- register_copy //SEG164 findcol::@13 @@ -9087,9 +10019,8 @@ findcol: { inx //SEG166 [78] if((byte) findcol::i#1<(byte) numpoints#1) goto findcol::@1 [ render::x#2 render::y#2 render::colline#2 findcol::i#1 findcol::mindiff#11 findcol::mincol#2 findcol::x#0 findcol::y#0 numpoints#1 ] -- xby_lt_zpby1_then_la1 cpx $8 - bcc b1_from_b13 + bcc b1 //SEG167 [79] phi from findcol::@13 to findcol::@return - breturn_from_b13: //SEG168 [79] phi (byte) findcol::return#0 = (byte) findcol::mincol#2 -- register_copy jmp breturn //SEG169 [79] phi from findcol::@2 to findcol::@return @@ -9107,7 +10038,6 @@ findcol: { //SEG175 [82] (byte~) findcol::diff#13 ← (byte) findcol::diff#6 [ render::x#2 render::y#2 render::colline#2 findcol::i#12 findcol::x#0 findcol::y#0 findcol::mincol#1 findcol::diff#13 numpoints#1 ] -- zpby1=aby sta $6 //SEG176 [76] phi from findcol::@12 to findcol::@13 - b13_from_b12: //SEG177 [76] phi (byte) findcol::mindiff#11 = (byte~) findcol::diff#13 -- register_copy //SEG178 [76] phi (byte) findcol::mincol#2 = (byte) findcol::mincol#1 -- register_copy jmp b13 @@ -9121,7 +10051,6 @@ findcol: { clc adc $7 //SEG182 [74] phi from findcol::@9 to findcol::@11 - b11_from_b9: //SEG183 [74] phi (byte) findcol::diff#6 = (byte) findcol::diff#2 -- register_copy jmp b11 //SEG184 findcol::@6 @@ -9132,7 +10061,6 @@ findcol: { sbc $9 sta $7 //SEG186 [70] phi from findcol::@6 to findcol::@8 - b8_from_b6: //SEG187 [70] phi (byte) findcol::diff#4 = (byte) findcol::diff#0 -- register_copy jmp b8 //SEG188 findcol::@2 @@ -9146,14 +10074,12 @@ findcol: { //SEG190 initscreen initscreen: { //SEG191 [87] phi from initscreen to initscreen::@1 - b1_from_initscreen: //SEG192 [87] phi (byte*) initscreen::screen#2 = (word) 1024 -- zpptrby1=cowo1 lda #<$400 sta $3 lda #>$400 sta $3+$1 //SEG193 [87] phi from initscreen::@1 to initscreen::@1 - b1_from_b1: //SEG194 [87] phi (byte*) initscreen::screen#2 = (byte*) initscreen::screen#1 -- register_copy //SEG195 initscreen::@1 b1: @@ -9169,14 +10095,13 @@ initscreen: { //SEG198 [90] if((byte*) initscreen::screen#1<(word) 2024) goto initscreen::@1 [ initscreen::screen#1 ] -- zpptrby1_lt_cowo1_then_la1 lda $3+$1 cmp #>$7e8 - bcc b1_from_b1 + bcc b1 bne !+ lda $3 cmp #<$7e8 - bcc b1_from_b1 + bcc b1 !: //SEG199 initscreen::@return - breturn: //SEG200 [91] return [ ] rts } @@ -9196,7 +10121,6 @@ addpoint: { //SEG205 [96] (byte) numpoints#1 ← ++ (byte) numpoints#19 [ ] -- zpby1=_inc_zpby1 inc $8 //SEG206 addpoint::@return - breturn: //SEG207 [97] return [ ] rts }