1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-19 15:29:48 +00:00

Implemented ASM long label relabelling. Closes #57

This commit is contained in:
jespergravgaard 2017-12-03 15:12:20 +01:00
parent defd957837
commit b43489f11a
13 changed files with 1349 additions and 47 deletions

View File

@ -327,6 +327,7 @@ public class Compiler {
pass5Optimizations.add(new Pass5UnusedLabelElimination(program));
pass5Optimizations.add(new Pass5DoubleJumpElimination(program));
pass5Optimizations.add(new Pass5UnreachableCodeElimination(program));
pass5Optimizations.add(new Pass5RelabelLongLabels(program));
boolean asmOptimized = true;
while (asmOptimized) {
asmOptimized = false;

View File

@ -45,4 +45,7 @@ public class AsmLabel implements AsmLine {
return getAsm();
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -0,0 +1,113 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.asm.*;
import dk.camelot64.kickc.model.Program;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
* Relabel long labels in ASM code
*/
public class Pass5RelabelLongLabels extends Pass5AsmOptimization {
public Pass5RelabelLongLabels(Program program) {
super(program);
}
public boolean optimize() {
boolean optimized = false;
// Find all labels
// Scope->Set<Labels>
Map<String, Set<String>> allLabels = new LinkedHashMap<>();
String currentScope = "";
for (AsmSegment asmSegment : getAsmProgram().getSegments()) {
for (AsmLine asmLine : asmSegment.getLines()) {
if (asmLine instanceof AsmScopeBegin) {
currentScope = ((AsmScopeBegin) asmLine).getLabel();
} else if (asmLine instanceof AsmScopeEnd) {
currentScope = "";
} else if (asmLine instanceof AsmLabel) {
AsmLabel asmLabel = (AsmLabel) asmLine;
Set<String> scopeLabels = allLabels.get(currentScope);
if (scopeLabels == null) {
scopeLabels = new LinkedHashSet<>();
allLabels.put(currentScope, scopeLabels);
}
scopeLabels.add(asmLabel.getLabel());
}
}
}
// Find relabels for all long labels
// Scope->(Label->NewLabel)
Map<String, Map<String, String>> relabels = new LinkedHashMap<>();
for (AsmSegment asmSegment : getAsmProgram().getSegments()) {
for (AsmLine asmLine : asmSegment.getLines()) {
if (asmLine instanceof AsmScopeBegin) {
currentScope = ((AsmScopeBegin) asmLine).getLabel();
} else if (asmLine instanceof AsmScopeEnd) {
currentScope = "";
} else if (asmLine instanceof AsmLabel) {
AsmLabel asmLabel = (AsmLabel) asmLine;
if (asmLabel.getLabel().contains("_from_")) {
// Found a long label
Set<String> scopeLabels = allLabels.get(currentScope);
Map<String, String> scopeRelabels = relabels.get(currentScope);
if (scopeRelabels == null) {
scopeRelabels = new LinkedHashMap<>();
relabels.put(currentScope, scopeRelabels);
}
// Find new short unused label
int labelIdx = 1;
String newLabel = "b" + labelIdx;
while (scopeLabels.contains(newLabel) || scopeRelabels.containsValue(newLabel)) {
newLabel = "b" + labelIdx++;
}
getLog().append("Relabelling long label " + asmLabel.getLabel() + " to " + newLabel);
scopeRelabels.put(asmLabel.getLabel(), newLabel);
asmLabel.setLabel(newLabel);
}
}
}
}
// Execute relabelling
for (AsmSegment asmSegment : getAsmProgram().getSegments()) {
for (AsmLine asmLine : asmSegment.getLines()) {
if (asmLine instanceof AsmScopeBegin) {
currentScope = ((AsmScopeBegin) asmLine).getLabel();
} else if (asmLine instanceof AsmScopeEnd) {
currentScope = "";
} else if (asmLine instanceof AsmLabel) {
AsmLabel asmLabel = (AsmLabel) asmLine;
Map<String, String> scopeRelabels = relabels.get(currentScope);
if (scopeRelabels != null) {
String newLabel = scopeRelabels.get(asmLabel.getLabel());
if (newLabel != null) {
asmLabel.setLabel(newLabel);
}
}
} else if (asmLine instanceof AsmInstruction) {
AsmInstruction asmInstruction = (AsmInstruction) asmLine;
if (asmInstruction.getType().isJump()) {
String parameter = asmInstruction.getParameter();
Map<String, String> scopeRelabels = relabels.get(currentScope);
if (scopeRelabels != null) {
String newLabel = scopeRelabels.get(parameter);
if (newLabel != null) {
asmInstruction.setParameter(newLabel);
}
}
}
}
}
}
return relabels.size() > 0;
}
}

View File

@ -28,10 +28,10 @@ main: {
lda bits
and #$80
cmp #0
beq b3_from_b2
beq b4
lda #'*'
jmp b3
b3_from_b2:
b4:
lda #'.'
b3:
ldy #0

View File

@ -2354,6 +2354,125 @@ main: {
rts
}
Relabelling long label b3_from_b2 to b4
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
.const PROCPORT = 1
.const CHARGEN = $d000
.const SCREEN = $400
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main param-assignment [ ] ( )
jsr main
//SEG6 [3] phi from @1 to @end [phi:@1->@end]
//SEG7 @end
//SEG8 main
main: {
.const CHAR_A = CHARGEN+8
.label bits = 3
.label sc = 4
.label y = 2
//SEG9 asm { sei }
sei
//SEG10 [5] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 50 [ ] ( main:2 [ ] ) -- _deref_cowo1=coby2
lda #$32
sta PROCPORT
//SEG11 [6] phi from main to main::@1 [phi:main->main::@1]
//SEG12 [6] phi (byte*) main::sc#7 = (const byte*) SCREEN#0 [phi:main->main::@1#0] -- zpptrby1=cowo1
lda #<SCREEN
sta sc
lda #>SCREEN
sta sc+1
//SEG13 [6] phi (byte) main::y#2 = (byte/signed byte/word/signed word) 0 [phi:main->main::@1#1] -- zpby1=coby1
lda #0
sta y
jmp b1
//SEG14 [6] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
//SEG15 [6] phi (byte*) main::sc#7 = (byte*) main::sc#2 [phi:main::@5->main::@1#0] -- register_copy
//SEG16 [6] phi (byte) main::y#2 = (byte) main::y#1 [phi:main::@5->main::@1#1] -- register_copy
//SEG17 main::@1
b1:
//SEG18 [7] (byte) main::bits#0 ← (const byte*) main::CHAR_A#0 *idx (byte) main::y#2 [ main::y#2 main::sc#7 main::bits#0 ] ( main:2 [ main::y#2 main::sc#7 main::bits#0 ] ) -- zpby1=cowo1_derefidx_zpby2
ldx y
lda CHAR_A,x
sta bits
//SEG19 [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
//SEG20 [8] phi (byte) main::x#2 = (byte/signed byte/word/signed word) 0 [phi:main::@1->main::@2#0] -- xby=coby1
ldx #0
//SEG21 [8] phi (byte*) main::sc#3 = (byte*) main::sc#7 [phi:main::@1->main::@2#1] -- register_copy
//SEG22 [8] phi (byte) main::bits#2 = (byte) main::bits#0 [phi:main::@1->main::@2#2] -- register_copy
jmp b2
//SEG23 [8] phi from main::@3 to main::@2 [phi:main::@3->main::@2]
//SEG24 [8] phi (byte) main::x#2 = (byte) main::x#1 [phi:main::@3->main::@2#0] -- register_copy
//SEG25 [8] phi (byte*) main::sc#3 = (byte*) main::sc#1 [phi:main::@3->main::@2#1] -- register_copy
//SEG26 [8] phi (byte) main::bits#2 = (byte) main::bits#1 [phi:main::@3->main::@2#2] -- register_copy
//SEG27 main::@2
b2:
//SEG28 [9] (byte~) main::$2 ← (byte) main::bits#2 & (byte/word/signed word) 128 [ main::y#2 main::bits#2 main::sc#3 main::x#2 main::$2 ] ( main:2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 main::$2 ] ) -- aby=zpby1_band_coby1
lda bits
and #$80
//SEG29 [10] if((byte~) main::$2==(byte/signed byte/word/signed word) 0) goto main::@3 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ( main:2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b4
//SEG30 [11] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
//SEG31 main::@4
//SEG32 [12] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
//SEG33 [12] phi (byte) main::c#2 = (byte) '*' [phi:main::@4->main::@3#0] -- aby=coby1
lda #'*'
jmp b3
//SEG34 [12] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
b4:
//SEG35 [12] phi (byte) main::c#2 = (byte) '.' [phi:main::@2->main::@3#0] -- aby=coby1
lda #'.'
//SEG36 main::@3
b3:
//SEG37 [13] *((byte*) main::sc#3) ← (byte) main::c#2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ( main:2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ) -- _deref_zpptrby1=aby
ldy #0
sta (sc),y
//SEG38 [14] (byte*) main::sc#1 ← ++ (byte*) main::sc#3 [ main::y#2 main::bits#2 main::x#2 main::sc#1 ] ( main:2 [ main::y#2 main::bits#2 main::x#2 main::sc#1 ] ) -- zpptrby1=_inc_zpptrby1
inc sc
bne !+
inc sc+1
!:
//SEG39 [15] (byte) main::bits#1 ← (byte) main::bits#2 << (byte/signed byte/word/signed word) 1 [ main::y#2 main::x#2 main::bits#1 main::sc#1 ] ( main:2 [ main::y#2 main::x#2 main::bits#1 main::sc#1 ] ) -- zpby1=zpby1_rol_1
asl bits
//SEG40 [16] (byte) main::x#1 ← ++ (byte) main::x#2 [ main::y#2 main::bits#1 main::sc#1 main::x#1 ] ( main:2 [ main::y#2 main::bits#1 main::sc#1 main::x#1 ] ) -- xby=_inc_xby
inx
//SEG41 [17] if((byte) main::x#1!=(byte/signed byte/word/signed word) 8) goto main::@2 [ main::y#2 main::bits#1 main::sc#1 main::x#1 ] ( main:2 [ main::y#2 main::bits#1 main::sc#1 main::x#1 ] ) -- xby_neq_coby1_then_la1
cpx #8
bne b2
//SEG42 main::@5
//SEG43 [18] (byte*) main::sc#2 ← (byte*) main::sc#1 + (byte/signed byte/word/signed word) 32 [ main::y#2 main::sc#2 ] ( main:2 [ main::y#2 main::sc#2 ] ) -- zpptrby1=zpptrby1_plus_coby1
lda sc
clc
adc #$20
sta sc
bcc !+
inc sc+1
!:
//SEG44 [19] (byte) main::y#1 ← ++ (byte) main::y#2 [ main::y#1 main::sc#2 ] ( main:2 [ main::y#1 main::sc#2 ] ) -- zpby1=_inc_zpby1
inc y
//SEG45 [20] if((byte) main::y#1!=(byte/signed byte/word/signed word) 8) goto main::@1 [ main::y#1 main::sc#2 ] ( main:2 [ main::y#1 main::sc#2 ] ) -- zpby1_neq_coby1_then_la1
lda y
cmp #8
bne b1
//SEG46 main::@6
//SEG47 [21] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 55 [ ] ( main:2 [ ] ) -- _deref_cowo1=coby2
lda #$37
sta PROCPORT
//SEG48 asm { cli }
cli
//SEG49 main::@return
//SEG50 [23] return [ ] ( main:2 [ ] )
rts
}
Removing instruction jmp b1
Removing instruction jmp b2
Succesful ASM optimization Pass5NextJumpElimination
@ -2418,7 +2537,7 @@ main: {
and #$80
//SEG29 [10] if((byte~) main::$2==(byte/signed byte/word/signed word) 0) goto main::@3 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ( main:2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG30 [11] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
//SEG31 main::@4
//SEG32 [12] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
@ -2426,7 +2545,7 @@ main: {
lda #'*'
jmp b3
//SEG34 [12] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
b3_from_b2:
b4:
//SEG35 [12] phi (byte) main::c#2 = (byte) '.' [phi:main::@2->main::@3#0] -- aby=coby1
lda #'.'
//SEG36 main::@3
@ -2579,7 +2698,7 @@ main: {
and #$80
//SEG29 [10] if((byte~) main::$2==(byte/signed byte/word/signed word) 0) goto main::@3 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ( main:2 [ main::y#2 main::bits#2 main::sc#3 main::x#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG30 [11] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
//SEG31 main::@4
//SEG32 [12] phi from main::@4 to main::@3 [phi:main::@4->main::@3]
@ -2587,7 +2706,7 @@ main: {
lda #'*'
jmp b3
//SEG34 [12] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
b3_from_b2:
b4:
//SEG35 [12] phi (byte) main::c#2 = (byte) '.' [phi:main::@2->main::@3#0] -- aby=coby1
lda #'.'
//SEG36 main::@3

View File

@ -8,7 +8,7 @@
jsr main
main: {
jsr prepare
b3_from_b11:
b1:
ldx #$19
b3:
lda RASTER
@ -23,7 +23,7 @@ main: {
bne b3
jsr flip
jsr plot
jmp b3_from_b11
jmp b1
}
plot: {
.label line = 2

View File

@ -5968,14 +5968,9 @@ 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
Relabelling long label b3_from_b11 to b1
Relabelling long label b3_from_b3 to b2
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
@ -6000,12 +5995,13 @@ main: {
//SEG11 [47] phi from main to prepare [phi:main->prepare]
jsr prepare
//SEG12 [6] phi from main main::@11 to main::@3 [phi:main/main::@11->main::@3]
b3_from_b11:
b1:
//SEG13 [6] phi (byte) main::c#4 = (byte/signed byte/word/signed word) 25 [phi:main/main::@11->main::@3#0] -- xby=coby1
ldx #$19
jmp b3
//SEG14 [6] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
b3_from_b3:
b2:
jmp b3
//SEG15 [6] phi from main::@6 to main::@3 [phi:main::@6->main::@3]
//SEG16 [6] phi (byte) main::c#4 = (byte) main::c#1 [phi:main::@6->main::@3#0] -- register_copy
//SEG17 main::@3
@ -6038,7 +6034,242 @@ main: {
jsr plot
//SEG32 main::@11
//SEG33 [15] if(true) goto main::@3 [ ] ( main:2 [ ] ) -- true_then_la1
jmp b3_from_b11
jmp b1
//SEG34 main::@return
//SEG35 [16] return [ ] ( main:2 [ ] )
}
//SEG36 plot
plot: {
.label line = 2
.label y = 4
//SEG37 [18] phi from plot to plot::@1 [phi:plot->plot::@1]
//SEG38 [18] phi (byte) plot::y#4 = (byte/signed byte/word/signed word) 16 [phi:plot->plot::@1#0] -- zpby1=coby1
lda #$10
sta y
//SEG39 [18] phi (byte*) plot::line#4 = (const byte[1000]) SCREEN#0+(byte/signed byte/word/signed word) 5*(byte/signed byte/word/signed word) 40+(byte/signed byte/word/signed word) 12 [phi:plot->plot::@1#1] -- zpptrby1=cowo1
lda #<SCREEN+5*$28+$c
sta line
lda #>SCREEN+5*$28+$c
sta line+1
//SEG40 [18] phi (byte) plot::i#3 = (byte/signed byte/word/signed word) 0 [phi:plot->plot::@1#2] -- xby=coby1
ldx #0
jmp b1
//SEG41 [18] phi from plot::@3 to plot::@1 [phi:plot::@3->plot::@1]
//SEG42 [18] phi (byte) plot::y#4 = (byte) plot::y#1 [phi:plot::@3->plot::@1#0] -- register_copy
//SEG43 [18] phi (byte*) plot::line#4 = (byte*) plot::line#1 [phi:plot::@3->plot::@1#1] -- register_copy
//SEG44 [18] phi (byte) plot::i#3 = (byte) plot::i#1 [phi:plot::@3->plot::@1#2] -- register_copy
//SEG45 plot::@1
b1:
//SEG46 [19] phi from plot::@1 to plot::@2 [phi:plot::@1->plot::@2]
//SEG47 [19] phi (byte) plot::x#2 = (byte/signed byte/word/signed word) 0 [phi:plot::@1->plot::@2#0] -- yby=coby1
ldy #0
//SEG48 [19] phi (byte) plot::i#2 = (byte) plot::i#3 [phi:plot::@1->plot::@2#1] -- register_copy
jmp b2
//SEG49 [19] phi from plot::@2 to plot::@2 [phi:plot::@2->plot::@2]
//SEG50 [19] phi (byte) plot::x#2 = (byte) plot::x#1 [phi:plot::@2->plot::@2#0] -- register_copy
//SEG51 [19] phi (byte) plot::i#2 = (byte) plot::i#1 [phi:plot::@2->plot::@2#1] -- register_copy
//SEG52 plot::@2
b2:
//SEG53 [20] (byte~) plot::$3 ← (const byte[256]) buffer1#0 *idx (byte) plot::i#2 [ plot::line#4 plot::y#4 plot::i#2 plot::x#2 plot::$3 ] ( main:2::plot:14 [ plot::line#4 plot::y#4 plot::i#2 plot::x#2 plot::$3 ] ) -- aby=cowo1_derefidx_xby
lda buffer1,x
//SEG54 [21] *((byte*) plot::line#4 + (byte) plot::x#2) ← (byte~) plot::$3 [ plot::line#4 plot::y#4 plot::i#2 plot::x#2 ] ( main:2::plot:14 [ plot::line#4 plot::y#4 plot::i#2 plot::x#2 ] ) -- zpptrby1_derefidx_yby=aby
sta (line),y
//SEG55 [22] (byte) plot::i#1 ← ++ (byte) plot::i#2 [ plot::line#4 plot::y#4 plot::i#1 plot::x#2 ] ( main:2::plot:14 [ plot::line#4 plot::y#4 plot::i#1 plot::x#2 ] ) -- xby=_inc_xby
inx
//SEG56 [23] (byte) plot::x#1 ← ++ (byte) plot::x#2 [ plot::line#4 plot::y#4 plot::i#1 plot::x#1 ] ( main:2::plot:14 [ plot::line#4 plot::y#4 plot::i#1 plot::x#1 ] ) -- yby=_inc_yby
iny
//SEG57 [24] if((byte) plot::x#1<(byte/signed byte/word/signed word) 16) goto plot::@2 [ plot::line#4 plot::y#4 plot::i#1 plot::x#1 ] ( main:2::plot:14 [ plot::line#4 plot::y#4 plot::i#1 plot::x#1 ] ) -- yby_lt_coby1_then_la1
cpy #$10
bcc b2
//SEG58 plot::@3
//SEG59 [25] (byte*) plot::line#1 ← (byte*) plot::line#4 + (byte/signed byte/word/signed word) 40 [ plot::y#4 plot::i#1 plot::line#1 ] ( main:2::plot:14 [ plot::y#4 plot::i#1 plot::line#1 ] ) -- zpptrby1=zpptrby1_plus_coby1
lda line
clc
adc #$28
sta line
bcc !+
inc line+1
!:
//SEG60 [26] (byte) plot::y#1 ← -- (byte) plot::y#4 [ plot::i#1 plot::line#1 plot::y#1 ] ( main:2::plot:14 [ plot::i#1 plot::line#1 plot::y#1 ] ) -- zpby1=_dec_zpby1
dec y
//SEG61 [27] if((byte) plot::y#1!=(byte/signed byte/word/signed word) 0) goto plot::@1 [ plot::i#1 plot::line#1 plot::y#1 ] ( main:2::plot:14 [ plot::i#1 plot::line#1 plot::y#1 ] ) -- zpby1_neq_0_then_la1
lda y
bne b1
//SEG62 plot::@return
//SEG63 [28] return [ ] ( main:2::plot:14 [ ] )
rts
}
//SEG64 flip
flip: {
.label c = 5
.label r = 4
//SEG65 [30] phi from flip to flip::@1 [phi:flip->flip::@1]
//SEG66 [30] phi (byte) flip::r#4 = (byte/signed byte/word/signed word) 16 [phi:flip->flip::@1#0] -- zpby1=coby1
lda #$10
sta r
//SEG67 [30] phi (byte) flip::dstIdx#5 = (byte/signed byte/word/signed word) 15 [phi:flip->flip::@1#1] -- yby=coby1
ldy #$f
//SEG68 [30] phi (byte) flip::srcIdx#3 = (byte/signed byte/word/signed word) 0 [phi:flip->flip::@1#2] -- xby=coby1
ldx #0
jmp b1
//SEG69 [30] phi from flip::@4 to flip::@1 [phi:flip::@4->flip::@1]
//SEG70 [30] phi (byte) flip::r#4 = (byte) flip::r#1 [phi:flip::@4->flip::@1#0] -- register_copy
//SEG71 [30] phi (byte) flip::dstIdx#5 = (byte) flip::dstIdx#2 [phi:flip::@4->flip::@1#1] -- register_copy
//SEG72 [30] phi (byte) flip::srcIdx#3 = (byte) flip::srcIdx#1 [phi:flip::@4->flip::@1#2] -- register_copy
//SEG73 flip::@1
b1:
//SEG74 [31] phi from flip::@1 to flip::@2 [phi:flip::@1->flip::@2]
//SEG75 [31] phi (byte) flip::c#2 = (byte/signed byte/word/signed word) 16 [phi:flip::@1->flip::@2#0] -- zpby1=coby1
lda #$10
sta c
//SEG76 [31] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#5 [phi:flip::@1->flip::@2#1] -- register_copy
//SEG77 [31] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#3 [phi:flip::@1->flip::@2#2] -- register_copy
jmp b2
//SEG78 [31] phi from flip::@2 to flip::@2 [phi:flip::@2->flip::@2]
//SEG79 [31] phi (byte) flip::c#2 = (byte) flip::c#1 [phi:flip::@2->flip::@2#0] -- register_copy
//SEG80 [31] phi (byte) flip::dstIdx#3 = (byte) flip::dstIdx#1 [phi:flip::@2->flip::@2#1] -- register_copy
//SEG81 [31] phi (byte) flip::srcIdx#2 = (byte) flip::srcIdx#1 [phi:flip::@2->flip::@2#2] -- register_copy
//SEG82 flip::@2
b2:
//SEG83 [32] (byte~) flip::$0 ← (const byte[256]) buffer1#0 *idx (byte) flip::srcIdx#2 [ flip::r#4 flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::$0 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#2 flip::dstIdx#3 flip::c#2 flip::$0 ] ) -- aby=cowo1_derefidx_xby
lda buffer1,x
//SEG84 [33] *((const byte[256]) buffer2#0 + (byte) flip::dstIdx#3) ← (byte~) flip::$0 [ flip::r#4 flip::srcIdx#2 flip::dstIdx#3 flip::c#2 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#2 flip::dstIdx#3 flip::c#2 ] ) -- cowo1_derefidx_yby=aby
sta buffer2,y
//SEG85 [34] (byte) flip::srcIdx#1 ← ++ (byte) flip::srcIdx#2 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#3 flip::c#2 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#3 flip::c#2 ] ) -- xby=_inc_xby
inx
//SEG86 [35] (byte) flip::dstIdx#1 ← (byte) flip::dstIdx#3 + (byte/signed byte/word/signed word) 16 [ flip::r#4 flip::srcIdx#1 flip::c#2 flip::dstIdx#1 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#1 flip::c#2 flip::dstIdx#1 ] ) -- yby=yby_plus_coby1
tya
clc
adc #$10
tay
//SEG87 [36] (byte) flip::c#1 ← -- (byte) flip::c#2 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#1 flip::c#1 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#1 flip::c#1 ] ) -- zpby1=_dec_zpby1
dec c
//SEG88 [37] if((byte) flip::c#1!=(byte/signed byte/word/signed word) 0) goto flip::@2 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#1 flip::c#1 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#1 flip::c#1 ] ) -- zpby1_neq_0_then_la1
lda c
bne b2
//SEG89 flip::@4
//SEG90 [38] (byte) flip::dstIdx#2 ← -- (byte) flip::dstIdx#1 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#2 ] ( main:2::flip:12 [ flip::r#4 flip::srcIdx#1 flip::dstIdx#2 ] ) -- yby=_dec_yby
dey
//SEG91 [39] (byte) flip::r#1 ← -- (byte) flip::r#4 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] ( main:2::flip:12 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] ) -- zpby1=_dec_zpby1
dec r
//SEG92 [40] if((byte) flip::r#1!=(byte/signed byte/word/signed word) 0) goto flip::@1 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] ( main:2::flip:12 [ flip::srcIdx#1 flip::dstIdx#2 flip::r#1 ] ) -- zpby1_neq_0_then_la1
lda r
bne b1
//SEG93 [41] phi from flip::@4 to flip::@3 [phi:flip::@4->flip::@3]
//SEG94 [41] phi (byte) flip::i#2 = (byte/signed byte/word/signed word) 0 [phi:flip::@4->flip::@3#0] -- xby=coby1
ldx #0
jmp b3
//SEG95 [41] phi from flip::@3 to flip::@3 [phi:flip::@3->flip::@3]
//SEG96 [41] phi (byte) flip::i#2 = (byte) flip::i#1 [phi:flip::@3->flip::@3#0] -- register_copy
//SEG97 flip::@3
b3:
//SEG98 [42] (byte~) flip::$4 ← (const byte[256]) buffer2#0 *idx (byte) flip::i#2 [ flip::i#2 flip::$4 ] ( main:2::flip:12 [ flip::i#2 flip::$4 ] ) -- aby=cowo1_derefidx_xby
lda buffer2,x
//SEG99 [43] *((const byte[256]) buffer1#0 + (byte) flip::i#2) ← (byte~) flip::$4 [ flip::i#2 ] ( main:2::flip:12 [ flip::i#2 ] ) -- cowo1_derefidx_xby=aby
sta buffer1,x
//SEG100 [44] (byte) flip::i#1 ← ++ (byte) flip::i#2 [ flip::i#1 ] ( main:2::flip:12 [ flip::i#1 ] ) -- xby=_inc_xby
inx
//SEG101 [45] if((byte) flip::i#1!=(byte/signed byte/word/signed word) 0) goto flip::@3 [ flip::i#1 ] ( main:2::flip:12 [ flip::i#1 ] ) -- xby_neq_0_then_la1
cpx #0
bne b3
//SEG102 flip::@return
//SEG103 [46] return [ ] ( main:2::flip:12 [ ] )
rts
}
//SEG104 prepare
prepare: {
//SEG105 [48] phi from prepare to prepare::@1 [phi:prepare->prepare::@1]
//SEG106 [48] phi (byte) prepare::i#2 = (byte/signed byte/word/signed word) 0 [phi:prepare->prepare::@1#0] -- xby=coby1
ldx #0
jmp b1
//SEG107 [48] phi from prepare::@1 to prepare::@1 [phi:prepare::@1->prepare::@1]
//SEG108 [48] phi (byte) prepare::i#2 = (byte) prepare::i#1 [phi:prepare::@1->prepare::@1#0] -- register_copy
//SEG109 prepare::@1
b1:
//SEG110 [49] *((const byte[256]) buffer1#0 + (byte) prepare::i#2) ← (byte) prepare::i#2 [ prepare::i#2 ] ( main:2::prepare:5 [ prepare::i#2 ] ) -- cowo1_derefidx_xby=xby
txa
sta buffer1,x
//SEG111 [50] (byte) prepare::i#1 ← ++ (byte) prepare::i#2 [ prepare::i#1 ] ( main:2::prepare:5 [ prepare::i#1 ] ) -- xby=_inc_xby
inx
//SEG112 [51] if((byte) prepare::i#1!=(byte/signed byte/word/signed word) 0) goto prepare::@1 [ prepare::i#1 ] ( main:2::prepare:5 [ prepare::i#1 ] ) -- xby_neq_0_then_la1
cpx #0
bne b1
//SEG113 prepare::@return
//SEG114 [52] return [ ] ( main:2::prepare:5 [ ] )
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
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
.const SCREEN = $400
.const buffer1 = $1000
.const buffer2 = $1100
.const RASTER = $d012
//SEG2 @begin
//SEG3 [1] phi from @begin to @4 [phi:@begin->@4]
//SEG4 @4
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @4 to main [phi:@4->main]
jsr main
//SEG7 [3] phi from @4 to @end [phi:@4->@end]
//SEG8 @end
//SEG9 main
main: {
//SEG10 [5] call prepare param-assignment [ ] ( main:2 [ ] )
//SEG11 [47] phi from main to prepare [phi:main->prepare]
jsr prepare
//SEG12 [6] phi from main main::@11 to main::@3 [phi:main/main::@11->main::@3]
b1:
//SEG13 [6] phi (byte) main::c#4 = (byte/signed byte/word/signed word) 25 [phi:main/main::@11->main::@3#0] -- xby=coby1
ldx #$19
jmp b3
//SEG14 [6] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
b2:
//SEG15 [6] phi from main::@6 to main::@3 [phi:main::@6->main::@3]
//SEG16 [6] phi (byte) main::c#4 = (byte) main::c#1 [phi:main::@6->main::@3#0] -- register_copy
//SEG17 main::@3
b3:
//SEG18 [7] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 254) goto main::@3 [ main::c#4 ] ( main:2 [ main::c#4 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$fe
bne b3
//SEG19 main::@4
b4:
//SEG20 [8] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 255) goto main::@4 [ main::c#4 ] ( main:2 [ main::c#4 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$ff
bne b4
//SEG21 main::@6
//SEG22 [9] (byte) main::c#1 ← -- (byte) main::c#4 [ main::c#1 ] ( main:2 [ main::c#1 ] ) -- xby=_dec_xby
dex
//SEG23 [10] if((byte) main::c#1!=(byte/signed byte/word/signed word) 0) goto main::@3 [ main::c#1 ] ( main:2 [ main::c#1 ] ) -- xby_neq_0_then_la1
cpx #0
bne b3
//SEG24 [11] phi from main::@6 to main::@7 [phi:main::@6->main::@7]
//SEG25 main::@7
//SEG26 [12] call flip param-assignment [ ] ( main:2 [ ] )
//SEG27 [29] phi from main::@7 to flip [phi:main::@7->flip]
jsr flip
//SEG28 [13] phi from main::@7 to main::@10 [phi:main::@7->main::@10]
//SEG29 main::@10
//SEG30 [14] call plot param-assignment [ ] ( main:2 [ ] )
//SEG31 [17] phi from main::@10 to plot [phi:main::@10->plot]
jsr plot
//SEG32 main::@11
//SEG33 [15] if(true) goto main::@3 [ ] ( main:2 [ ] ) -- true_then_la1
jmp b1
//SEG34 main::@return
//SEG35 [16] return [ ] ( main:2 [ ] )
}
@ -6197,7 +6428,7 @@ prepare: {
rts
}
Removing instruction b3_from_b3:
Removing instruction b2:
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 Basic Upstart
@ -6223,7 +6454,7 @@ main: {
//SEG11 [47] phi from main to prepare [phi:main->prepare]
jsr prepare
//SEG12 [6] phi from main main::@11 to main::@3 [phi:main/main::@11->main::@3]
b3_from_b11:
b1:
//SEG13 [6] phi (byte) main::c#4 = (byte/signed byte/word/signed word) 25 [phi:main/main::@11->main::@3#0] -- xby=coby1
ldx #$19
jmp b3
@ -6260,7 +6491,7 @@ main: {
jsr plot
//SEG32 main::@11
//SEG33 [15] if(true) goto main::@3 [ ] ( main:2 [ ] ) -- true_then_la1
jmp b3_from_b11
jmp b1
//SEG34 main::@return
//SEG35 [16] return [ ] ( main:2 [ ] )
}
@ -6445,7 +6676,7 @@ main: {
//SEG11 [47] phi from main to prepare [phi:main->prepare]
jsr prepare
//SEG12 [6] phi from main main::@11 to main::@3 [phi:main/main::@11->main::@3]
b3_from_b11:
b1:
//SEG13 [6] phi (byte) main::c#4 = (byte/signed byte/word/signed word) 25 [phi:main/main::@11->main::@3#0] -- xby=coby1
ldx #$19
//SEG14 [6] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
@ -6481,7 +6712,7 @@ main: {
jsr plot
//SEG32 main::@11
//SEG33 [15] if(true) goto main::@3 [ ] ( main:2 [ ] ) -- true_then_la1
jmp b3_from_b11
jmp b1
//SEG34 main::@return
//SEG35 [16] return [ ] ( main:2 [ ] )
}
@ -6753,7 +6984,7 @@ main: {
//SEG11 [47] phi from main to prepare [phi:main->prepare]
jsr prepare
//SEG12 [6] phi from main main::@11 to main::@3 [phi:main/main::@11->main::@3]
b3_from_b11:
b1:
//SEG13 [6] phi (byte) main::c#4 = (byte/signed byte/word/signed word) 25 [phi:main/main::@11->main::@3#0] -- xby=coby1
ldx #$19
//SEG14 [6] phi from main::@3 to main::@3 [phi:main::@3->main::@3]
@ -6789,7 +7020,7 @@ main: {
jsr plot
//SEG32 main::@11
//SEG33 [15] if(true) goto main::@3 [ ] ( main:2 [ ] ) -- true_then_la1
jmp b3_from_b11
jmp b1
//SEG34 main::@return
//SEG35 [16] return [ ] ( main:2 [ ] )
}

View File

@ -51,10 +51,10 @@ main: {
tax
lda bits_count,x
cmp #2
bcc b2_from_b1
bcc b7
lda #0+1
jmp b2
b2_from_b1:
b7:
lda #0
b2:
asl

View File

@ -5159,6 +5159,250 @@ main: {
rts
}
Relabelling long label b2_from_b1 to b7
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
.const SCREEN = $400
.const CHARGEN = $d000
.const PROCPORT = 1
.const D018 = $d018
.const CHARSET4 = $2800
bits_count: .byte 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main param-assignment [ ] ( )
jsr main
//SEG6 [3] phi from @1 to @end [phi:@1->@end]
//SEG7 @end
//SEG8 main
main: {
.label _1 = 6
.label _12 = 9
.label _23 = 9
.label _33 = 9
.label chargen1 = 7
.label bits_gen = 6
.label charset4 = 4
.label chargen = 2
//SEG9 asm { sei }
sei
//SEG10 [5] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 50 [ ] ( main:2 [ ] ) -- _deref_cowo1=coby2
lda #$32
sta PROCPORT
//SEG11 [6] phi from main to main::@1 [phi:main->main::@1]
//SEG12 [6] phi (byte*) main::charset4#10 = (const byte*) CHARSET4#0 [phi:main->main::@1#0] -- zpptrby1=cowo1
lda #<CHARSET4
sta charset4
lda #>CHARSET4
sta charset4+1
//SEG13 [6] phi (byte*) main::chargen#10 = (const byte*) CHARGEN#0 [phi:main->main::@1#1] -- zpptrby1=cowo1
lda #<CHARGEN
sta chargen
lda #>CHARGEN
sta chargen+1
jmp b1
//SEG14 [6] phi from main::@5 to main::@1 [phi:main::@5->main::@1]
//SEG15 [6] phi (byte*) main::charset4#10 = (byte*) main::charset4#1 [phi:main::@5->main::@1#0] -- register_copy
//SEG16 [6] phi (byte*) main::chargen#10 = (byte*) main::chargen#1 [phi:main::@5->main::@1#1] -- register_copy
//SEG17 main::@1
b1:
//SEG18 [7] (byte*) main::chargen1#0 ← (byte*) main::chargen#10 + (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ) -- zpptrby1=zpptrby2_plus_1
lda chargen
clc
adc #1
sta chargen1
lda chargen+1
adc #0
sta chargen1+1
//SEG19 [8] (byte~) main::$1 ← *((byte*) main::chargen#10) & (byte/signed byte/word/signed word) 96 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 ] ) -- zpby1=_deref_zpptrby1_band_coby1
ldy #0
lda (chargen),y
and #$60
sta _1
//SEG20 [9] (byte~) main::$2 ← *((byte*) main::chargen1#0) & (byte/signed byte/word/signed word) 96 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 main::$2 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 main::$2 ] ) -- aby=_deref_zpptrby1_band_coby1
lda (chargen1),y
and #$60
//SEG21 [10] (byte~) main::$3 ← (byte~) main::$2 >> (byte/signed byte/word/signed word) 2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 main::$3 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$1 main::$3 ] ) -- aby=aby_ror_2
lsr
lsr
//SEG22 [11] (byte~) main::$4 ← (byte~) main::$1 | (byte~) main::$3 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$4 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$4 ] ) -- aby=zpby1_bor_aby
ora _1
//SEG23 [12] (byte~) main::$5 ← (byte~) main::$4 >> (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$5 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$5 ] ) -- aby=aby_ror_1
lsr
//SEG24 [13] (byte~) main::$6 ← (byte~) main::$5 >> (byte/signed byte/word/signed word) 2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$6 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::$6 ] ) -- aby=aby_ror_2
lsr
lsr
//SEG25 [14] (byte) main::bits#0 ← (const byte[]) bits_count#0 *idx (byte~) main::$6 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits#0 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits#0 ] ) -- aby=cowo1_derefidx_aby
tax
lda bits_count,x
//SEG26 [15] if((byte) main::bits#0<(byte/signed byte/word/signed word) 2) goto main::@2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b7
//SEG27 [16] phi from main::@1 to main::@7 [phi:main::@1->main::@7]
//SEG28 main::@7
//SEG29 [17] phi from main::@7 to main::@2 [phi:main::@7->main::@2]
//SEG30 [17] phi (byte) main::bits_gen#9 = (byte/signed byte/word/signed word) 0+(byte/signed byte/word/signed word) 1 [phi:main::@7->main::@2#0] -- aby=coby1
lda #0+1
jmp b2
//SEG31 [17] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
b7:
//SEG32 [17] phi (byte) main::bits_gen#9 = (byte/signed byte/word/signed word) 0 [phi:main::@1->main::@2#0] -- aby=coby1
lda #0
//SEG33 main::@2
b2:
//SEG34 [18] (byte) main::bits_gen#1 ← (byte) main::bits_gen#9 << (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 ] ) -- zpby1=aby_rol_1
asl
sta bits_gen
//SEG35 [19] (byte~) main::$12 ← *((byte*) main::chargen#10) & (byte/signed byte/word/signed word) 24 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 ] ) -- zpby1=_deref_zpptrby1_band_coby1
ldy #0
lda (chargen),y
and #$18
sta _12
//SEG36 [20] (byte~) main::$13 ← *((byte*) main::chargen1#0) & (byte/signed byte/word/signed word) 24 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 main::$13 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 main::$13 ] ) -- aby=_deref_zpptrby1_band_coby1
lda (chargen1),y
and #$18
//SEG37 [21] (byte~) main::$14 ← (byte~) main::$13 >> (byte/signed byte/word/signed word) 2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 main::$14 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$12 main::$14 ] ) -- aby=aby_ror_2
lsr
lsr
//SEG38 [22] (byte~) main::$15 ← (byte~) main::$12 | (byte~) main::$14 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$15 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$15 ] ) -- aby=zpby1_bor_aby
ora _12
//SEG39 [23] (byte~) main::$16 ← (byte~) main::$15 >> (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$16 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::$16 ] ) -- aby=aby_ror_1
lsr
//SEG40 [24] (byte) main::bits#1 ← (const byte[]) bits_count#0 *idx (byte~) main::$16 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::bits#1 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 main::bits#1 ] ) -- aby=cowo1_derefidx_aby
tax
lda bits_count,x
//SEG41 [25] if((byte) main::bits#1<(byte/signed byte/word/signed word) 2) goto main::@3 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#1 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b3
//SEG42 main::@8
//SEG43 [26] (byte) main::bits_gen#4 ← (byte) main::bits_gen#1 + (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#4 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#4 ] ) -- zpby1=zpby1_plus_1
inc bits_gen
//SEG44 [27] phi from main::@2 main::@8 to main::@3 [phi:main::@2/main::@8->main::@3]
//SEG45 [27] phi (byte) main::bits_gen#11 = (byte) main::bits_gen#1 [phi:main::@2/main::@8->main::@3#0] -- register_copy
//SEG46 main::@3
b3:
//SEG47 [28] (byte) main::bits_gen#14 ← (byte) main::bits_gen#11 << (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 ] ) -- zpby1=zpby1_rol_1
asl bits_gen
//SEG48 [29] (byte~) main::$22 ← *((byte*) main::chargen#10) & (byte/signed byte/word/signed word) 6 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$22 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$22 ] ) -- aby=_deref_zpptrby1_band_coby1
ldy #0
lda (chargen),y
and #6
//SEG49 [30] (byte~) main::$23 ← (byte~) main::$22 << (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 ] ) -- zpby1=aby_rol_1
asl
sta _23
//SEG50 [31] (byte~) main::$24 ← *((byte*) main::chargen1#0) & (byte/signed byte/word/signed word) 6 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 main::$24 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 main::$24 ] ) -- aby=_deref_zpptrby1_band_coby1
lda (chargen1),y
and #6
//SEG51 [32] (byte~) main::$25 ← (byte~) main::$24 >> (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 main::$25 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$23 main::$25 ] ) -- aby=aby_ror_1
lsr
//SEG52 [33] (byte~) main::$26 ← (byte~) main::$23 | (byte~) main::$25 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$26 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::$26 ] ) -- aby=zpby1_bor_aby
ora _23
//SEG53 [34] (byte) main::bits#2 ← (const byte[]) bits_count#0 *idx (byte~) main::$26 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::bits#2 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 main::bits#2 ] ) -- aby=cowo1_derefidx_aby
tax
lda bits_count,x
//SEG54 [35] if((byte) main::bits#2<(byte/signed byte/word/signed word) 2) goto main::@4 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#14 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b4
//SEG55 main::@9
//SEG56 [36] (byte) main::bits_gen#6 ← (byte) main::bits_gen#14 + (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#6 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#6 ] ) -- zpby1=zpby1_plus_1
inc bits_gen
//SEG57 [37] phi from main::@3 main::@9 to main::@4 [phi:main::@3/main::@9->main::@4]
//SEG58 [37] phi (byte) main::bits_gen#13 = (byte) main::bits_gen#14 [phi:main::@3/main::@9->main::@4#0] -- register_copy
//SEG59 main::@4
b4:
//SEG60 [38] (byte) main::bits_gen#16 ← (byte) main::bits_gen#13 << (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 ] ) -- zpby1=zpby1_rol_1
asl bits_gen
//SEG61 [39] (byte~) main::$32 ← *((byte*) main::chargen#10) & (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 main::$32 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 main::$32 ] ) -- aby=_deref_zpptrby1_band_coby1
ldy #0
lda (chargen),y
and #1
//SEG62 [40] (byte~) main::$33 ← (byte~) main::$32 << (byte/signed byte/word/signed word) 2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 main::$33 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 main::bits_gen#16 main::$33 ] ) -- zpby1=aby_rol_2
asl
asl
sta _33
//SEG63 [41] (byte~) main::$34 ← *((byte*) main::chargen1#0) & (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::$33 main::$34 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::$33 main::$34 ] ) -- aby=_deref_zpptrby1_band_coby1
lda (chargen1),y
and #1
//SEG64 [42] (byte~) main::$35 ← (byte~) main::$33 | (byte~) main::$34 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::$35 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::$35 ] ) -- aby=zpby1_bor_aby
ora _33
//SEG65 [43] (byte) main::bits#3 ← (const byte[]) bits_count#0 *idx (byte~) main::$35 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::bits#3 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#16 main::bits#3 ] ) -- aby=cowo1_derefidx_aby
tax
lda bits_count,x
//SEG66 [44] if((byte) main::bits#3<(byte/signed byte/word/signed word) 2) goto main::@5 [ main::chargen#10 main::charset4#10 main::bits_gen#16 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#16 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b5
//SEG67 main::@10
//SEG68 [45] (byte) main::bits_gen#8 ← (byte) main::bits_gen#16 + (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::bits_gen#8 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#8 ] ) -- zpby1=zpby1_plus_1
inc bits_gen
//SEG69 [46] phi from main::@10 main::@4 to main::@5 [phi:main::@10/main::@4->main::@5]
//SEG70 [46] phi (byte) main::bits_gen#15 = (byte) main::bits_gen#8 [phi:main::@10/main::@4->main::@5#0] -- register_copy
//SEG71 main::@5
b5:
//SEG72 [47] (byte) main::bits_gen#7 ← (byte) main::bits_gen#15 << (byte/signed byte/word/signed word) 1 [ main::chargen#10 main::charset4#10 main::bits_gen#7 ] ( main:2 [ main::chargen#10 main::charset4#10 main::bits_gen#7 ] ) -- aby=zpby1_rol_1
lda bits_gen
asl
//SEG73 [48] *((byte*) main::charset4#10) ← (byte) main::bits_gen#7 [ main::chargen#10 main::charset4#10 ] ( main:2 [ main::chargen#10 main::charset4#10 ] ) -- _deref_zpptrby1=aby
ldy #0
sta (charset4),y
//SEG74 [49] (byte*) main::charset4#1 ← ++ (byte*) main::charset4#10 [ main::chargen#10 main::charset4#1 ] ( main:2 [ main::chargen#10 main::charset4#1 ] ) -- zpptrby1=_inc_zpptrby1
inc charset4
bne !+
inc charset4+1
!:
//SEG75 [50] (byte*) main::chargen#1 ← (byte*) main::chargen#10 + (byte/signed byte/word/signed word) 2 [ main::chargen#1 main::charset4#1 ] ( main:2 [ main::chargen#1 main::charset4#1 ] ) -- zpptrby1=zpptrby1_plus_coby1
lda chargen
clc
adc #2
sta chargen
bcc !+
inc chargen+1
!:
//SEG76 [51] if((byte*) main::chargen#1<(const byte*) CHARGEN#0+(word/signed word) 2048) goto main::@1 [ main::chargen#1 main::charset4#1 ] ( main:2 [ main::chargen#1 main::charset4#1 ] ) -- zpptrby1_lt_cowo1_then_la1
lda chargen+1
cmp #>CHARGEN+$800
bcc b1
bne !+
lda chargen
cmp #<CHARGEN+$800
bcc b1
!:
//SEG77 main::@11
//SEG78 [52] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 55 [ ] ( main:2 [ ] ) -- _deref_cowo1=coby2
lda #$37
sta PROCPORT
//SEG79 asm { cli }
cli
//SEG80 [54] phi from main::@11 to main::@6 [phi:main::@11->main::@6]
//SEG81 [54] phi (byte) main::i#2 = (byte/signed byte/word/signed word) 0 [phi:main::@11->main::@6#0] -- xby=coby1
ldx #0
jmp b6
//SEG82 [54] phi from main::@6 to main::@6 [phi:main::@6->main::@6]
//SEG83 [54] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@6->main::@6#0] -- register_copy
//SEG84 main::@6
b6:
//SEG85 [55] *((const byte*) SCREEN#0 + (byte) main::i#2) ← (byte) main::i#2 [ main::i#2 ] ( main:2 [ main::i#2 ] ) -- cowo1_derefidx_xby=xby
txa
sta SCREEN,x
//SEG86 [56] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- xby=_inc_xby
inx
//SEG87 [57] if((byte) main::i#1!=(byte/signed byte/word/signed word) 0) goto main::@6 [ main::i#1 ] ( main:2 [ main::i#1 ] ) -- xby_neq_0_then_la1
cpx #0
bne b6
//SEG88 main::@12
//SEG89 [58] *((const byte*) D018#0) ← (byte/signed byte/word/signed word) 25 [ ] ( main:2 [ ] ) -- _deref_cowo1=coby2
lda #$19
sta D018
//SEG90 main::@return
//SEG91 [59] return [ ] ( main:2 [ ] )
rts
}
Removing instruction jmp b1
Removing instruction jmp b6
Succesful ASM optimization Pass5NextJumpElimination
@ -5243,7 +5487,7 @@ main: {
lda bits_count,x
//SEG26 [15] if((byte) main::bits#0<(byte/signed byte/word/signed word) 2) goto main::@2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b2_from_b1
bcc b7
//SEG27 [16] phi from main::@1 to main::@7 [phi:main::@1->main::@7]
//SEG28 main::@7
//SEG29 [17] phi from main::@7 to main::@2 [phi:main::@7->main::@2]
@ -5251,7 +5495,7 @@ main: {
lda #0+1
jmp b2
//SEG31 [17] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
b2_from_b1:
b7:
//SEG32 [17] phi (byte) main::bits_gen#9 = (byte/signed byte/word/signed word) 0 [phi:main::@1->main::@2#0] -- aby=coby1
lda #0
//SEG33 main::@2
@ -5591,7 +5835,7 @@ main: {
lda bits_count,x
//SEG26 [15] if((byte) main::bits#0<(byte/signed byte/word/signed word) 2) goto main::@2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ( main:2 [ main::chargen#10 main::charset4#10 main::chargen1#0 ] ) -- aby_lt_coby1_then_la1
cmp #2
bcc b2_from_b1
bcc b7
//SEG27 [16] phi from main::@1 to main::@7 [phi:main::@1->main::@7]
//SEG28 main::@7
//SEG29 [17] phi from main::@7 to main::@2 [phi:main::@7->main::@2]
@ -5599,7 +5843,7 @@ main: {
lda #0+1
jmp b2
//SEG31 [17] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
b2_from_b1:
b7:
//SEG32 [17] phi (byte) main::bits_gen#9 = (byte/signed byte/word/signed word) 0 [phi:main::@1->main::@2#0] -- aby=coby1
lda #0
//SEG33 main::@2

View File

@ -1048,7 +1048,61 @@ main: {
jmp b1
}
Removing instruction b1_from_b8:
Relabelling long label b1_from_b8 to b3
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @1 to main [phi:@1->main]
jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
//SEG8 @end
//SEG9 main
main: {
//SEG10 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG11 [5] phi (byte) main::s#3 = (byte/signed byte/word/signed word) 0 [phi:main->main::@1#0] -- yby=coby1
ldy #0
//SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word) 100 [phi:main->main::@1#1] -- xby=coby1
ldx #$64
//SEG13 main::@1
b1:
//SEG14 [6] (byte) main::i#1 ← -- (byte) main::i#2 [ main::s#3 main::i#1 ] ( main:2 [ main::s#3 main::i#1 ] ) -- xby=_dec_xby
dex
//SEG15 [7] if((byte) main::i#1>(byte/signed byte/word/signed word) 0) goto main::@2 [ main::s#3 main::i#1 ] ( main:2 [ main::s#3 main::i#1 ] ) -- xby_gt_0_then_la1
cpx #0
bne b2
//SEG16 main::@return
//SEG17 [8] return [ ] ( main:2 [ ] )
rts
//SEG18 main::@2
b2:
//SEG19 [9] if((byte) main::i#1<=(byte/signed byte/word/signed word) 50) goto main::@4 [ main::s#3 main::i#1 ] ( main:2 [ main::s#3 main::i#1 ] ) -- xby_le_coby1_then_la1
cpx #$32
bcc b4
beq b4
//SEG20 main::@8
//SEG21 [10] (byte) main::s#2 ← ++ (byte) main::s#3 [ main::i#1 main::s#2 ] ( main:2 [ main::i#1 main::s#2 ] ) -- yby=_inc_yby
iny
//SEG22 [5] phi from main::@4 main::@8 to main::@1 [phi:main::@4/main::@8->main::@1]
b3:
//SEG23 [5] phi (byte) main::s#3 = (byte) main::s#1 [phi:main::@4/main::@8->main::@1#0] -- register_copy
//SEG24 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4/main::@8->main::@1#1] -- register_copy
jmp b1
//SEG25 main::@4
b4:
//SEG26 [11] (byte) main::s#1 ← -- (byte) main::s#3 [ main::i#1 main::s#1 ] ( main:2 [ main::i#1 main::s#1 ] ) -- yby=_dec_yby
dey
jmp b1
}
Removing instruction b3:
Succesful ASM optimization Pass5UnusedLabelElimination
ASSEMBLER
//SEG0 Basic Upstart

View File

@ -4613,6 +4613,174 @@ fillscreen: {
rts
}
Relabelling long label b2_from_b2 to b1
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
.const SCREEN = $400
.const RASTER = $d012
.const BGCOL = $d020
.const SCROLL = $d016
TEXT: .text "-= this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. =- @"
//SEG2 @begin
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
//SEG4 @2
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @2 to main [phi:@2->main]
jsr main
//SEG7 [3] phi from @2 to @end [phi:@2->@end]
//SEG8 @end
//SEG9 main
main: {
.const line = SCREEN+$28
.label nxt = 2
//SEG10 [5] call fillscreen param-assignment [ ] ( main:2 [ ] )
//SEG11 [28] phi from main to fillscreen [phi:main->fillscreen]
jsr fillscreen
//SEG12 [6] phi from main to main::@2 [phi:main->main::@2]
//SEG13 [6] phi (byte*) main::nxt#9 = (const byte*) TEXT#0 [phi:main->main::@2#0] -- zpptrby1=cowo1
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
//SEG14 [6] phi (byte) main::scroll#7 = (byte/signed byte/word/signed word) 7 [phi:main->main::@2#1] -- xby=coby1
ldx #7
jmp b2
//SEG15 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b1:
jmp b2
//SEG16 [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
//SEG17 [6] phi (byte*) main::nxt#9 = (byte*) main::nxt#10 [phi:main::@4->main::@2#0] -- register_copy
//SEG18 [6] phi (byte) main::scroll#7 = (byte) main::scroll#10 [phi:main::@4->main::@2#1] -- register_copy
//SEG19 main::@2
b2:
//SEG20 [7] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 254) goto main::@2 [ main::scroll#7 main::nxt#9 ] ( main:2 [ main::scroll#7 main::nxt#9 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$fe
bne b2
//SEG21 main::@3
b3:
//SEG22 [8] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 255) goto main::@3 [ main::scroll#7 main::nxt#9 ] ( main:2 [ main::scroll#7 main::nxt#9 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$ff
bne b3
//SEG23 main::@8
//SEG24 [9] *((const byte*) BGCOL#0) ← ++ *((const byte*) BGCOL#0) [ main::scroll#7 main::nxt#9 ] ( main:2 [ main::scroll#7 main::nxt#9 ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG25 [10] (byte) main::scroll#1 ← -- (byte) main::scroll#7 [ main::nxt#9 main::scroll#1 ] ( main:2 [ main::nxt#9 main::scroll#1 ] ) -- xby=_dec_xby
dex
//SEG26 [11] if((byte) main::scroll#1!=(byte/word/signed word) 255) goto main::@4 [ main::nxt#9 main::scroll#1 ] ( main:2 [ main::nxt#9 main::scroll#1 ] ) -- xby_neq_coby1_then_la1
cpx #$ff
bne b4
//SEG27 [12] phi from main::@8 to main::@5 [phi:main::@8->main::@5]
//SEG28 [12] phi (byte) main::i#2 = (byte/signed byte/word/signed word) 0 [phi:main::@8->main::@5#0] -- xby=coby1
ldx #0
jmp b5
//SEG29 [12] phi from main::@5 to main::@5 [phi:main::@5->main::@5]
//SEG30 [12] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@5->main::@5#0] -- register_copy
//SEG31 main::@5
b5:
//SEG32 [13] (byte~) main::$7 ← (const byte[]) main::line#0+(byte/signed byte/word/signed word) 1 *idx (byte) main::i#2 [ main::nxt#9 main::i#2 main::$7 ] ( main:2 [ main::nxt#9 main::i#2 main::$7 ] ) -- aby=cowo1_derefidx_xby
lda line+1,x
//SEG33 [14] *((const byte[]) main::line#0 + (byte) main::i#2) ← (byte~) main::$7 [ main::nxt#9 main::i#2 ] ( main:2 [ main::nxt#9 main::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line,x
//SEG34 [15] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::nxt#9 main::i#1 ] ( main:2 [ main::nxt#9 main::i#1 ] ) -- xby=_inc_xby
inx
//SEG35 [16] if((byte) main::i#1!=(byte/signed byte/word/signed word) 39) goto main::@5 [ main::nxt#9 main::i#1 ] ( main:2 [ main::nxt#9 main::i#1 ] ) -- xby_neq_coby1_then_la1
cpx #$27
bne b5
//SEG36 main::@10
//SEG37 [17] (byte) main::c#0 ← *((byte*) main::nxt#9) [ main::nxt#9 main::c#0 ] ( main:2 [ main::nxt#9 main::c#0 ] ) -- xby=_deref_zpptrby1
ldy #0
lda (nxt),y
tax
//SEG38 [18] if((byte) main::c#0!=(byte) '@') goto main::@6 [ main::nxt#9 main::c#0 ] ( main:2 [ main::nxt#9 main::c#0 ] ) -- xby_neq_coby1_then_la1
cpx #'@'
bne b6
//SEG39 main::@11
//SEG40 [19] (byte) main::c#1 ← *((const byte*) TEXT#0) [ main::c#1 ] ( main:2 [ main::c#1 ] ) -- xby=_deref_cowo1
ldx TEXT
//SEG41 [20] phi from main::@11 to main::@6 [phi:main::@11->main::@6]
//SEG42 [20] phi (byte*) main::nxt#4 = (const byte*) TEXT#0 [phi:main::@11->main::@6#0] -- zpptrby1=cowo1
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
//SEG43 [20] phi (byte) main::c#2 = (byte) main::c#1 [phi:main::@11->main::@6#1] -- register_copy
jmp b6
//SEG44 [20] phi from main::@10 to main::@6 [phi:main::@10->main::@6]
//SEG45 [20] phi (byte*) main::nxt#4 = (byte*) main::nxt#9 [phi:main::@10->main::@6#0] -- register_copy
//SEG46 [20] phi (byte) main::c#2 = (byte) main::c#0 [phi:main::@10->main::@6#1] -- register_copy
//SEG47 main::@6
b6:
//SEG48 [21] *((const byte[]) main::line#0+(byte/signed byte/word/signed word) 39) ← (byte) main::c#2 [ main::nxt#4 ] ( main:2 [ main::nxt#4 ] ) -- _deref_cowo1=xby
stx line+$27
//SEG49 [22] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4 [ main::nxt#1 ] ( main:2 [ main::nxt#1 ] ) -- zpptrby1=_inc_zpptrby1
inc nxt
bne !+
inc nxt+1
!:
//SEG50 [23] phi from main::@6 to main::@4 [phi:main::@6->main::@4]
//SEG51 [23] phi (byte*) main::nxt#10 = (byte*) main::nxt#1 [phi:main::@6->main::@4#0] -- register_copy
//SEG52 [23] phi (byte) main::scroll#10 = (byte/signed byte/word/signed word) 7 [phi:main::@6->main::@4#1] -- xby=coby1
ldx #7
jmp b4
//SEG53 [23] phi from main::@8 to main::@4 [phi:main::@8->main::@4]
//SEG54 [23] phi (byte*) main::nxt#10 = (byte*) main::nxt#9 [phi:main::@8->main::@4#0] -- register_copy
//SEG55 [23] phi (byte) main::scroll#10 = (byte) main::scroll#1 [phi:main::@8->main::@4#1] -- register_copy
//SEG56 main::@4
b4:
//SEG57 [24] *((const byte*) SCROLL#0) ← (byte) main::scroll#10 [ main::scroll#10 main::nxt#10 ] ( main:2 [ main::scroll#10 main::nxt#10 ] ) -- _deref_cowo1=xby
stx SCROLL
//SEG58 [25] *((const byte*) BGCOL#0) ← -- *((const byte*) BGCOL#0) [ main::scroll#10 main::nxt#10 ] ( main:2 [ main::scroll#10 main::nxt#10 ] ) -- _deref_cowo1=_dec__deref_cowo1
dec BGCOL
//SEG59 [26] if(true) goto main::@2 [ main::scroll#10 main::nxt#10 ] ( main:2 [ main::scroll#10 main::nxt#10 ] ) -- true_then_la1
jmp b2
//SEG60 main::@return
//SEG61 [27] return [ ] ( main:2 [ ] )
}
//SEG62 fillscreen
fillscreen: {
.const fill = $20
.label cursor = 2
//SEG63 [29] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
//SEG64 [29] phi (byte*) fillscreen::cursor#2 = (const byte*) SCREEN#0 [phi:fillscreen->fillscreen::@1#0] -- zpptrby1=cowo1
lda #<SCREEN
sta cursor
lda #>SCREEN
sta cursor+1
jmp b1
//SEG65 [29] phi from fillscreen::@1 to fillscreen::@1 [phi:fillscreen::@1->fillscreen::@1]
//SEG66 [29] phi (byte*) fillscreen::cursor#2 = (byte*) fillscreen::cursor#1 [phi:fillscreen::@1->fillscreen::@1#0] -- register_copy
//SEG67 fillscreen::@1
b1:
//SEG68 [30] *((byte*) fillscreen::cursor#2) ← (const byte) fillscreen::fill#0 [ fillscreen::cursor#2 ] ( main:2::fillscreen:5 [ fillscreen::cursor#2 ] ) -- _deref_zpptrby1=coby1
ldy #0
lda #fill
sta (cursor),y
//SEG69 [31] (byte*) fillscreen::cursor#1 ← ++ (byte*) fillscreen::cursor#2 [ fillscreen::cursor#1 ] ( main:2::fillscreen:5 [ fillscreen::cursor#1 ] ) -- zpptrby1=_inc_zpptrby1
inc cursor
bne !+
inc cursor+1
!:
//SEG70 [32] if((byte*) fillscreen::cursor#1<(const byte*) SCREEN#0+(word/signed word) 1000) goto fillscreen::@1 [ fillscreen::cursor#1 ] ( main:2::fillscreen:5 [ fillscreen::cursor#1 ] ) -- zpptrby1_lt_cowo1_then_la1
lda cursor+1
cmp #>SCREEN+$3e8
bcc b1
bne !+
lda cursor
cmp #<SCREEN+$3e8
bcc b1
!:
//SEG71 fillscreen::@return
//SEG72 [33] return [ ] ( main:2::fillscreen:5 [ ] )
rts
}
Removing instruction jmp b2
Removing instruction jmp b5
Removing instruction jmp b6
@ -4655,7 +4823,7 @@ main: {
ldx #7
jmp b2
//SEG15 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b2_from_b2:
b1:
//SEG16 [6] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
//SEG17 [6] phi (byte*) main::nxt#9 = (byte*) main::nxt#10 [phi:main::@4->main::@2#0] -- register_copy
//SEG18 [6] phi (byte) main::scroll#7 = (byte) main::scroll#10 [phi:main::@4->main::@2#1] -- register_copy
@ -4780,7 +4948,7 @@ fillscreen: {
rts
}
Removing instruction b2_from_b2:
Removing instruction b1:
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 Basic Upstart

View File

@ -92,10 +92,10 @@ scroll_bit: {
lda (current_chargen),y
and current_bit
cmp #0
beq b3_from_b2
beq b4
lda #$80+' '
jmp b3
b3_from_b2:
b4:
lda #' '
b3:
ldy #0

View File

@ -11162,6 +11162,375 @@ fillscreen: {
rts
}
Relabelling long label b2_from_b2 to b1
Relabelling long label b3_from_b2 to b4
Succesful ASM optimization Pass5RelabelLongLabels
ASSEMBLER
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
.const PROCPORT = 1
.const CHARGEN = $d000
.const SCREEN = $400
.const RASTER = $d012
.const BGCOL = $d020
.const SCROLL = $d016
.label current_bit = 2
.label current_chargen = 3
.label nxt = 7
TEXT: .text "-= this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. =- @"
//SEG2 @begin
//SEG3 [1] phi from @begin to @6 [phi:@begin->@6]
//SEG4 @6
//SEG5 [2] call main param-assignment [ ] ( )
//SEG6 [4] phi from @6 to main [phi:@6->main]
jsr main
//SEG7 [3] phi from @6 to @end [phi:@6->@end]
//SEG8 @end
//SEG9 main
main: {
//SEG10 [5] call fillscreen param-assignment [ ] ( main:2 [ ] )
//SEG11 [76] phi from main to fillscreen [phi:main->fillscreen]
jsr fillscreen
//SEG12 [6] phi from main to main::@2 [phi:main->main::@2]
//SEG13 [6] phi (byte*) current_chargen#27 = (const byte*) CHARGEN#0 [phi:main->main::@2#0] -- zpptrby1=cowo1
lda #<CHARGEN
sta current_chargen
lda #>CHARGEN
sta current_chargen+1
//SEG14 [6] phi (byte*) nxt#31 = (const byte*) TEXT#0 [phi:main->main::@2#1] -- zpptrby1=cowo1
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
//SEG15 [6] phi (byte) current_bit#29 = (byte/signed byte/word/signed word) 1 [phi:main->main::@2#2] -- zpby1=coby1
lda #1
sta current_bit
//SEG16 [6] phi (byte) scroll#18 = (byte/signed byte/word/signed word) 7 [phi:main->main::@2#3] -- xby=coby1
ldx #7
jmp b2
//SEG17 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b1:
jmp b2
//SEG18 [6] phi from main::@8 to main::@2 [phi:main::@8->main::@2]
//SEG19 [6] phi (byte*) current_chargen#27 = (byte*) current_chargen#11 [phi:main::@8->main::@2#0] -- register_copy
//SEG20 [6] phi (byte*) nxt#31 = (byte*) nxt#14 [phi:main::@8->main::@2#1] -- register_copy
//SEG21 [6] phi (byte) current_bit#29 = (byte) current_bit#12 [phi:main::@8->main::@2#2] -- register_copy
//SEG22 [6] phi (byte) scroll#18 = (byte) scroll#10 [phi:main::@8->main::@2#3] -- register_copy
//SEG23 main::@2
b2:
//SEG24 [7] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 254) goto main::@2 [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ( main:2 [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$fe
bne b2
//SEG25 main::@3
b3:
//SEG26 [8] if(*((const byte*) RASTER#0)!=(byte/word/signed word) 255) goto main::@3 [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ( main:2 [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ) -- _deref_cowo1_neq_coby2_then_la1
lda RASTER
cmp #$ff
bne b3
//SEG27 main::@5
//SEG28 [9] *((const byte*) BGCOL#0) ← ++ *((const byte*) BGCOL#0) [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ( main:2 [ scroll#18 current_bit#29 nxt#31 current_chargen#27 ] ) -- _deref_cowo1=_inc__deref_cowo1
inc BGCOL
//SEG29 [10] call scroll_soft param-assignment [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ( main:2 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] )
jsr scroll_soft
//SEG30 main::@8
//SEG31 [11] *((const byte*) BGCOL#0) ← -- *((const byte*) BGCOL#0) [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ( main:2 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ) -- _deref_cowo1=_dec__deref_cowo1
dec BGCOL
//SEG32 [12] if(true) goto main::@2 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ( main:2 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ) -- true_then_la1
jmp b2
//SEG33 main::@return
//SEG34 [13] return [ ] ( main:2 [ ] )
}
//SEG35 scroll_soft
scroll_soft: {
//SEG36 [14] (byte) scroll#3 ← -- (byte) scroll#18 [ current_bit#29 nxt#31 current_chargen#27 scroll#3 ] ( main:2::scroll_soft:10 [ current_bit#29 nxt#31 current_chargen#27 scroll#3 ] ) -- xby=_dec_xby
dex
//SEG37 [15] if((byte) scroll#3!=(byte/word/signed word) 255) goto scroll_soft::@1 [ current_bit#29 nxt#31 current_chargen#27 scroll#3 ] ( main:2::scroll_soft:10 [ current_bit#29 nxt#31 current_chargen#27 scroll#3 ] ) -- xby_neq_coby1_then_la1
cpx #$ff
bne b1
//SEG38 [16] phi from scroll_soft to scroll_soft::@2 [phi:scroll_soft->scroll_soft::@2]
//SEG39 scroll_soft::@2
//SEG40 [17] call scroll_bit param-assignment [ current_bit#21 nxt#36 current_chargen#19 ] ( main:2::scroll_soft:10 [ current_bit#21 nxt#36 current_chargen#19 ] )
jsr scroll_bit
//SEG41 [18] phi from scroll_soft::@2 to scroll_soft::@1 [phi:scroll_soft::@2->scroll_soft::@1]
//SEG42 [18] phi (byte*) current_chargen#11 = (byte*) current_chargen#19 [phi:scroll_soft::@2->scroll_soft::@1#0] -- register_copy
//SEG43 [18] phi (byte*) nxt#14 = (byte*) nxt#36 [phi:scroll_soft::@2->scroll_soft::@1#1] -- register_copy
//SEG44 [18] phi (byte) current_bit#12 = (byte) current_bit#21 [phi:scroll_soft::@2->scroll_soft::@1#2] -- register_copy
//SEG45 [18] phi (byte) scroll#10 = (byte/signed byte/word/signed word) 7 [phi:scroll_soft::@2->scroll_soft::@1#3] -- xby=coby1
ldx #7
jmp b1
//SEG46 [18] phi from scroll_soft to scroll_soft::@1 [phi:scroll_soft->scroll_soft::@1]
//SEG47 [18] phi (byte*) current_chargen#11 = (byte*) current_chargen#27 [phi:scroll_soft->scroll_soft::@1#0] -- register_copy
//SEG48 [18] phi (byte*) nxt#14 = (byte*) nxt#31 [phi:scroll_soft->scroll_soft::@1#1] -- register_copy
//SEG49 [18] phi (byte) current_bit#12 = (byte) current_bit#29 [phi:scroll_soft->scroll_soft::@1#2] -- register_copy
//SEG50 [18] phi (byte) scroll#10 = (byte) scroll#3 [phi:scroll_soft->scroll_soft::@1#3] -- register_copy
//SEG51 scroll_soft::@1
b1:
//SEG52 [19] *((const byte*) SCROLL#0) ← (byte) scroll#10 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ( main:2::scroll_soft:10 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ) -- _deref_cowo1=xby
stx SCROLL
//SEG53 scroll_soft::@return
//SEG54 [20] return [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] ( main:2::scroll_soft:10 [ scroll#10 current_bit#12 nxt#14 current_chargen#11 ] )
rts
}
//SEG55 scroll_bit
scroll_bit: {
.label _4 = 9
.label _5 = 3
.label c = 9
.label sc = 5
//SEG56 [21] (byte~) scroll_bit::$0 ← (byte) current_bit#29 >> (byte/signed byte/word/signed word) 1 [ nxt#31 current_chargen#27 scroll_bit::$0 ] ( main:2::scroll_soft:10::scroll_bit:17 [ nxt#31 current_chargen#27 scroll_bit::$0 ] ) -- aby=zpby1_ror_1
lda current_bit
lsr
//SEG57 [22] (byte) current_bit#5 ← (byte~) scroll_bit::$0 [ nxt#31 current_chargen#27 current_bit#5 ] ( main:2::scroll_soft:10::scroll_bit:17 [ nxt#31 current_chargen#27 current_bit#5 ] ) -- zpby1=aby
sta current_bit
//SEG58 [23] if((byte) current_bit#5!=(byte/signed byte/word/signed word) 0) goto scroll_bit::@1 [ nxt#31 current_chargen#27 current_bit#5 ] ( main:2::scroll_soft:10::scroll_bit:17 [ nxt#31 current_chargen#27 current_bit#5 ] ) -- zpby1_neq_0_then_la1
bne b1
//SEG59 [24] phi from scroll_bit to scroll_bit::@4 [phi:scroll_bit->scroll_bit::@4]
//SEG60 scroll_bit::@4
//SEG61 [25] call next_char param-assignment [ next_char::c#2 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ next_char::c#2 nxt#19 ] )
jsr next_char
//SEG62 [26] (byte) next_char::return#0 ← (byte) next_char::c#2 [ next_char::return#0 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ next_char::return#0 nxt#19 ] )
// (byte) next_char::return#0 = (byte) next_char::c#2 // register copy reg byte a
//SEG63 scroll_bit::@8
//SEG64 [27] (byte~) scroll_bit::$3 ← (byte) next_char::return#0 [ scroll_bit::$3 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ scroll_bit::$3 nxt#19 ] )
// (byte~) scroll_bit::$3 = (byte) next_char::return#0 // register copy reg byte a
//SEG65 [28] (word) scroll_bit::c#0 ← ((word)) (byte~) scroll_bit::$3 [ scroll_bit::c#0 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ scroll_bit::c#0 nxt#19 ] ) -- zpwo1=_word_aby
sta c
lda #0
sta c+1
//SEG66 [29] (word~) scroll_bit::$4 ← (word) scroll_bit::c#0 << (byte/signed byte/word/signed word) 3 [ scroll_bit::$4 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ scroll_bit::$4 nxt#19 ] ) -- zpwo1=zpwo1_rol_3
asl _4
rol _4+1
asl _4
rol _4+1
asl _4
rol _4+1
//SEG67 [30] (byte*~) scroll_bit::$5 ← (const byte*) CHARGEN#0 + (word~) scroll_bit::$4 [ scroll_bit::$5 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ scroll_bit::$5 nxt#19 ] ) -- zpptrby1=cowo1_plus_zpwo1
lda #<CHARGEN
clc
adc _4
sta _5
lda #>CHARGEN
adc _4+1
sta _5+1
//SEG68 [31] (byte*) current_chargen#5 ← (byte*~) scroll_bit::$5 [ current_chargen#5 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_chargen#5 nxt#19 ] )
// (byte*) current_chargen#5 = (byte*~) scroll_bit::$5 // register copy zp ZP_PTR_BYTE:3
//SEG69 [32] phi from scroll_bit::@8 to scroll_bit::@1 [phi:scroll_bit::@8->scroll_bit::@1]
//SEG70 [32] phi (byte*) nxt#36 = (byte*) nxt#19 [phi:scroll_bit::@8->scroll_bit::@1#0] -- register_copy
//SEG71 [32] phi (byte) current_bit#21 = (byte/word/signed word) 128 [phi:scroll_bit::@8->scroll_bit::@1#1] -- zpby1=coby1
lda #$80
sta current_bit
//SEG72 [32] phi (byte*) current_chargen#19 = (byte*) current_chargen#5 [phi:scroll_bit::@8->scroll_bit::@1#2] -- register_copy
jmp b1
//SEG73 [32] phi from scroll_bit to scroll_bit::@1 [phi:scroll_bit->scroll_bit::@1]
//SEG74 [32] phi (byte*) nxt#36 = (byte*) nxt#31 [phi:scroll_bit->scroll_bit::@1#0] -- register_copy
//SEG75 [32] phi (byte) current_bit#21 = (byte) current_bit#5 [phi:scroll_bit->scroll_bit::@1#1] -- register_copy
//SEG76 [32] phi (byte*) current_chargen#19 = (byte*) current_chargen#27 [phi:scroll_bit->scroll_bit::@1#2] -- register_copy
//SEG77 scroll_bit::@1
b1:
//SEG78 [33] call scroll_hard param-assignment [ current_bit#21 nxt#36 current_chargen#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 ] )
//SEG79 [49] phi from scroll_bit::@1 to scroll_hard [phi:scroll_bit::@1->scroll_hard]
jsr scroll_hard
//SEG80 scroll_bit::@7
//SEG81 asm { sei }
sei
//SEG82 [35] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 50 [ current_bit#21 nxt#36 current_chargen#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 ] ) -- _deref_cowo1=coby2
lda #$32
sta PROCPORT
//SEG83 [36] phi from scroll_bit::@7 to scroll_bit::@2 [phi:scroll_bit::@7->scroll_bit::@2]
//SEG84 [36] phi (byte*) scroll_bit::sc#2 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word) 40+(byte/signed byte/word/signed word) 39 [phi:scroll_bit::@7->scroll_bit::@2#0] -- zpptrby1=cowo1
lda #<SCREEN+$28+$27
sta sc
lda #>SCREEN+$28+$27
sta sc+1
//SEG85 [36] phi (byte) scroll_bit::r#2 = (byte/signed byte/word/signed word) 0 [phi:scroll_bit::@7->scroll_bit::@2#1] -- xby=coby1
ldx #0
jmp b2
//SEG86 [36] phi from scroll_bit::@3 to scroll_bit::@2 [phi:scroll_bit::@3->scroll_bit::@2]
//SEG87 [36] phi (byte*) scroll_bit::sc#2 = (byte*) scroll_bit::sc#1 [phi:scroll_bit::@3->scroll_bit::@2#0] -- register_copy
//SEG88 [36] phi (byte) scroll_bit::r#2 = (byte) scroll_bit::r#1 [phi:scroll_bit::@3->scroll_bit::@2#1] -- register_copy
//SEG89 scroll_bit::@2
b2:
//SEG90 [37] (byte) scroll_bit::bits#0 ← (byte*) current_chargen#19 *idx (byte) scroll_bit::r#2 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 scroll_bit::bits#0 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 scroll_bit::bits#0 ] ) -- aby=zpptrby1_derefidx_xby
stx $ff
ldy $ff
lda (current_chargen),y
//SEG91 [38] (byte~) scroll_bit::$10 ← (byte) scroll_bit::bits#0 & (byte) current_bit#21 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 scroll_bit::$10 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 scroll_bit::$10 ] ) -- aby=aby_band_zpby1
and current_bit
//SEG92 [39] if((byte~) scroll_bit::$10==(byte/signed byte/word/signed word) 0) goto scroll_bit::@3 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b4
//SEG93 [40] phi from scroll_bit::@2 to scroll_bit::@5 [phi:scroll_bit::@2->scroll_bit::@5]
//SEG94 scroll_bit::@5
//SEG95 [41] phi from scroll_bit::@5 to scroll_bit::@3 [phi:scroll_bit::@5->scroll_bit::@3]
//SEG96 [41] phi (byte) scroll_bit::b#2 = (byte/word/signed word) 128+(byte) ' ' [phi:scroll_bit::@5->scroll_bit::@3#0] -- aby=coby1
lda #$80+' '
jmp b3
//SEG97 [41] phi from scroll_bit::@2 to scroll_bit::@3 [phi:scroll_bit::@2->scroll_bit::@3]
b4:
//SEG98 [41] phi (byte) scroll_bit::b#2 = (byte) ' ' [phi:scroll_bit::@2->scroll_bit::@3#0] -- aby=coby1
lda #' '
//SEG99 scroll_bit::@3
b3:
//SEG100 [42] *((byte*) scroll_bit::sc#2) ← (byte) scroll_bit::b#2 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- _deref_zpptrby1=aby
ldy #0
sta (sc),y
//SEG101 [43] (byte*) scroll_bit::sc#1 ← (byte*) scroll_bit::sc#2 + (byte/signed byte/word/signed word) 40 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#1 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#1 ] ) -- zpptrby1=zpptrby1_plus_coby1
lda sc
clc
adc #$28
sta sc
bcc !+
inc sc+1
!:
//SEG102 [44] (byte) scroll_bit::r#1 ← ++ (byte) scroll_bit::r#2 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#1 scroll_bit::sc#1 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#1 scroll_bit::sc#1 ] ) -- xby=_inc_xby
inx
//SEG103 [45] if((byte) scroll_bit::r#1!=(byte/signed byte/word/signed word) 8) goto scroll_bit::@2 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#1 scroll_bit::sc#1 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#1 scroll_bit::sc#1 ] ) -- xby_neq_coby1_then_la1
cpx #8
bne b2
//SEG104 scroll_bit::@6
//SEG105 [46] *((const byte*) PROCPORT#0) ← (byte/signed byte/word/signed word) 55 [ current_bit#21 nxt#36 current_chargen#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 ] ) -- _deref_cowo1=coby2
lda #$37
sta PROCPORT
//SEG106 asm { cli }
cli
//SEG107 scroll_bit::@return
//SEG108 [48] return [ current_bit#21 nxt#36 current_chargen#19 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 ] )
rts
}
//SEG109 scroll_hard
scroll_hard: {
.const line0 = SCREEN+$28*0
.const line1 = SCREEN+$28*1
.const line2 = SCREEN+$28*2
.const line3 = SCREEN+$28*3
.const line4 = SCREEN+$28*4
.const line5 = SCREEN+$28*5
.const line6 = SCREEN+$28*6
.const line7 = SCREEN+$28*7
//SEG110 [50] phi from scroll_hard to scroll_hard::@1 [phi:scroll_hard->scroll_hard::@1]
//SEG111 [50] phi (byte) scroll_hard::i#2 = (byte/signed byte/word/signed word) 0 [phi:scroll_hard->scroll_hard::@1#0] -- xby=coby1
ldx #0
jmp b1
//SEG112 [50] phi from scroll_hard::@1 to scroll_hard::@1 [phi:scroll_hard::@1->scroll_hard::@1]
//SEG113 [50] phi (byte) scroll_hard::i#2 = (byte) scroll_hard::i#1 [phi:scroll_hard::@1->scroll_hard::@1#0] -- register_copy
//SEG114 scroll_hard::@1
b1:
//SEG115 [51] (byte~) scroll_hard::$17 ← (const byte[]) scroll_hard::line0#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$17 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$17 ] ) -- aby=cowo1_derefidx_xby
lda line0+1,x
//SEG116 [52] *((const byte[]) scroll_hard::line0#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$17 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line0,x
//SEG117 [53] (byte~) scroll_hard::$19 ← (const byte[]) scroll_hard::line1#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$19 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$19 ] ) -- aby=cowo1_derefidx_xby
lda line1+1,x
//SEG118 [54] *((const byte[]) scroll_hard::line1#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$19 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line1,x
//SEG119 [55] (byte~) scroll_hard::$21 ← (const byte[]) scroll_hard::line2#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$21 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$21 ] ) -- aby=cowo1_derefidx_xby
lda line2+1,x
//SEG120 [56] *((const byte[]) scroll_hard::line2#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$21 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line2,x
//SEG121 [57] (byte~) scroll_hard::$23 ← (const byte[]) scroll_hard::line3#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$23 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$23 ] ) -- aby=cowo1_derefidx_xby
lda line3+1,x
//SEG122 [58] *((const byte[]) scroll_hard::line3#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$23 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line3,x
//SEG123 [59] (byte~) scroll_hard::$25 ← (const byte[]) scroll_hard::line4#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$25 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$25 ] ) -- aby=cowo1_derefidx_xby
lda line4+1,x
//SEG124 [60] *((const byte[]) scroll_hard::line4#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$25 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line4,x
//SEG125 [61] (byte~) scroll_hard::$27 ← (const byte[]) scroll_hard::line5#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$27 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$27 ] ) -- aby=cowo1_derefidx_xby
lda line5+1,x
//SEG126 [62] *((const byte[]) scroll_hard::line5#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$27 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line5,x
//SEG127 [63] (byte~) scroll_hard::$29 ← (const byte[]) scroll_hard::line6#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$29 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$29 ] ) -- aby=cowo1_derefidx_xby
lda line6+1,x
//SEG128 [64] *((const byte[]) scroll_hard::line6#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$29 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line6,x
//SEG129 [65] (byte~) scroll_hard::$31 ← (const byte[]) scroll_hard::line7#0+(byte/signed byte/word/signed word) 1 *idx (byte) scroll_hard::i#2 [ scroll_hard::i#2 scroll_hard::$31 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 scroll_hard::$31 ] ) -- aby=cowo1_derefidx_xby
lda line7+1,x
//SEG130 [66] *((const byte[]) scroll_hard::line7#0 + (byte) scroll_hard::i#2) ← (byte~) scroll_hard::$31 [ scroll_hard::i#2 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#2 ] ) -- cowo1_derefidx_xby=aby
sta line7,x
//SEG131 [67] (byte) scroll_hard::i#1 ← ++ (byte) scroll_hard::i#2 [ scroll_hard::i#1 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#1 ] ) -- xby=_inc_xby
inx
//SEG132 [68] if((byte) scroll_hard::i#1!=(byte/signed byte/word/signed word) 39) goto scroll_hard::@1 [ scroll_hard::i#1 ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 scroll_hard::i#1 ] ) -- xby_neq_coby1_then_la1
cpx #$27
bne b1
//SEG133 scroll_hard::@return
//SEG134 [69] return [ ] ( main:2::scroll_soft:10::scroll_bit:17::scroll_hard:33 [ current_bit#21 nxt#36 current_chargen#19 ] )
rts
}
//SEG135 next_char
next_char: {
//SEG136 [70] (byte) next_char::c#0 ← *((byte*) nxt#31) [ nxt#31 next_char::c#0 ] ( main:2::scroll_soft:10::scroll_bit:17::next_char:25 [ nxt#31 next_char::c#0 ] ) -- aby=_deref_zpptrby1
ldy #0
lda (nxt),y
//SEG137 [71] if((byte) next_char::c#0!=(byte) '@') goto next_char::@1 [ nxt#31 next_char::c#0 ] ( main:2::scroll_soft:10::scroll_bit:17::next_char:25 [ nxt#31 next_char::c#0 ] ) -- aby_neq_coby1_then_la1
cmp #'@'
bne b1
//SEG138 next_char::@2
//SEG139 [72] (byte) next_char::c#1 ← *((const byte*) TEXT#0) [ next_char::c#1 ] ( main:2::scroll_soft:10::scroll_bit:17::next_char:25 [ next_char::c#1 ] ) -- aby=_deref_cowo1
lda TEXT
//SEG140 [73] phi from next_char::@2 to next_char::@1 [phi:next_char::@2->next_char::@1]
//SEG141 [73] phi (byte) next_char::c#2 = (byte) next_char::c#1 [phi:next_char::@2->next_char::@1#0] -- register_copy
//SEG142 [73] phi (byte*) nxt#18 = (const byte*) TEXT#0 [phi:next_char::@2->next_char::@1#1] -- zpptrby1=cowo1
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
jmp b1
//SEG143 [73] phi from next_char to next_char::@1 [phi:next_char->next_char::@1]
//SEG144 [73] phi (byte) next_char::c#2 = (byte) next_char::c#0 [phi:next_char->next_char::@1#0] -- register_copy
//SEG145 [73] phi (byte*) nxt#18 = (byte*) nxt#31 [phi:next_char->next_char::@1#1] -- register_copy
//SEG146 next_char::@1
b1:
//SEG147 [74] (byte*) nxt#19 ← ++ (byte*) nxt#18 [ next_char::c#2 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17::next_char:25 [ next_char::c#2 nxt#19 ] ) -- zpptrby1=_inc_zpptrby1
inc nxt
bne !+
inc nxt+1
!:
//SEG148 next_char::@return
//SEG149 [75] return [ next_char::c#2 nxt#19 ] ( main:2::scroll_soft:10::scroll_bit:17::next_char:25 [ next_char::c#2 nxt#19 ] )
rts
}
//SEG150 fillscreen
fillscreen: {
.const fill = $20
.label cursor = 3
//SEG151 [77] phi from fillscreen to fillscreen::@1 [phi:fillscreen->fillscreen::@1]
//SEG152 [77] phi (byte*) fillscreen::cursor#2 = (const byte*) SCREEN#0 [phi:fillscreen->fillscreen::@1#0] -- zpptrby1=cowo1
lda #<SCREEN
sta cursor
lda #>SCREEN
sta cursor+1
jmp b1
//SEG153 [77] phi from fillscreen::@1 to fillscreen::@1 [phi:fillscreen::@1->fillscreen::@1]
//SEG154 [77] phi (byte*) fillscreen::cursor#2 = (byte*) fillscreen::cursor#1 [phi:fillscreen::@1->fillscreen::@1#0] -- register_copy
//SEG155 fillscreen::@1
b1:
//SEG156 [78] *((byte*) fillscreen::cursor#2) ← (const byte) fillscreen::fill#0 [ fillscreen::cursor#2 ] ( main:2::fillscreen:5 [ fillscreen::cursor#2 ] ) -- _deref_zpptrby1=coby1
ldy #0
lda #fill
sta (cursor),y
//SEG157 [79] (byte*) fillscreen::cursor#1 ← ++ (byte*) fillscreen::cursor#2 [ fillscreen::cursor#1 ] ( main:2::fillscreen:5 [ fillscreen::cursor#1 ] ) -- zpptrby1=_inc_zpptrby1
inc cursor
bne !+
inc cursor+1
!:
//SEG158 [80] if((byte*) fillscreen::cursor#1<(const byte*) SCREEN#0+(word/signed word) 1000) goto fillscreen::@1 [ fillscreen::cursor#1 ] ( main:2::fillscreen:5 [ fillscreen::cursor#1 ] ) -- zpptrby1_lt_cowo1_then_la1
lda cursor+1
cmp #>SCREEN+$3e8
bcc b1
bne !+
lda cursor
cmp #<SCREEN+$3e8
bcc b1
!:
//SEG159 fillscreen::@return
//SEG160 [81] return [ ] ( main:2::fillscreen:5 [ ] )
rts
}
Removing instruction jmp b2
Removing instruction jmp b1
Removing instruction jmp b1
@ -11217,7 +11586,7 @@ main: {
ldx #7
jmp b2
//SEG17 [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
b2_from_b2:
b1:
//SEG18 [6] phi from main::@8 to main::@2 [phi:main::@8->main::@2]
//SEG19 [6] phi (byte*) current_chargen#27 = (byte*) current_chargen#11 [phi:main::@8->main::@2#0] -- register_copy
//SEG20 [6] phi (byte*) nxt#31 = (byte*) nxt#14 [phi:main::@8->main::@2#1] -- register_copy
@ -11363,7 +11732,7 @@ scroll_bit: {
and current_bit
//SEG92 [39] if((byte~) scroll_bit::$10==(byte/signed byte/word/signed word) 0) goto scroll_bit::@3 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG93 [40] phi from scroll_bit::@2 to scroll_bit::@5 [phi:scroll_bit::@2->scroll_bit::@5]
//SEG94 scroll_bit::@5
//SEG95 [41] phi from scroll_bit::@5 to scroll_bit::@3 [phi:scroll_bit::@5->scroll_bit::@3]
@ -11371,7 +11740,7 @@ scroll_bit: {
lda #$80+' '
jmp b3
//SEG97 [41] phi from scroll_bit::@2 to scroll_bit::@3 [phi:scroll_bit::@2->scroll_bit::@3]
b3_from_b2:
b4:
//SEG98 [41] phi (byte) scroll_bit::b#2 = (byte) ' ' [phi:scroll_bit::@2->scroll_bit::@3#0] -- aby=coby1
lda #' '
//SEG99 scroll_bit::@3
@ -11529,7 +11898,7 @@ fillscreen: {
rts
}
Removing instruction b2_from_b2:
Removing instruction b1:
Succesful ASM optimization Pass5RedundantLabelElimination
ASSEMBLER
//SEG0 Basic Upstart
@ -11723,7 +12092,7 @@ scroll_bit: {
and current_bit
//SEG92 [39] if((byte~) scroll_bit::$10==(byte/signed byte/word/signed word) 0) goto scroll_bit::@3 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG93 [40] phi from scroll_bit::@2 to scroll_bit::@5 [phi:scroll_bit::@2->scroll_bit::@5]
//SEG94 scroll_bit::@5
//SEG95 [41] phi from scroll_bit::@5 to scroll_bit::@3 [phi:scroll_bit::@5->scroll_bit::@3]
@ -11731,7 +12100,7 @@ scroll_bit: {
lda #$80+' '
jmp b3
//SEG97 [41] phi from scroll_bit::@2 to scroll_bit::@3 [phi:scroll_bit::@2->scroll_bit::@3]
b3_from_b2:
b4:
//SEG98 [41] phi (byte) scroll_bit::b#2 = (byte) ' ' [phi:scroll_bit::@2->scroll_bit::@3#0] -- aby=coby1
lda #' '
//SEG99 scroll_bit::@3
@ -12082,7 +12451,7 @@ scroll_bit: {
and current_bit
//SEG92 [39] if((byte~) scroll_bit::$10==(byte/signed byte/word/signed word) 0) goto scroll_bit::@3 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG93 [40] phi from scroll_bit::@2 to scroll_bit::@5 [phi:scroll_bit::@2->scroll_bit::@5]
//SEG94 scroll_bit::@5
//SEG95 [41] phi from scroll_bit::@5 to scroll_bit::@3 [phi:scroll_bit::@5->scroll_bit::@3]
@ -12090,7 +12459,7 @@ scroll_bit: {
lda #$80+' '
jmp b3
//SEG97 [41] phi from scroll_bit::@2 to scroll_bit::@3 [phi:scroll_bit::@2->scroll_bit::@3]
b3_from_b2:
b4:
//SEG98 [41] phi (byte) scroll_bit::b#2 = (byte) ' ' [phi:scroll_bit::@2->scroll_bit::@3#0] -- aby=coby1
lda #' '
//SEG99 scroll_bit::@3
@ -12588,7 +12957,7 @@ scroll_bit: {
and current_bit
//SEG92 [39] if((byte~) scroll_bit::$10==(byte/signed byte/word/signed word) 0) goto scroll_bit::@3 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ( main:2::scroll_soft:10::scroll_bit:17 [ current_bit#21 nxt#36 current_chargen#19 scroll_bit::r#2 scroll_bit::sc#2 ] ) -- aby_eq_0_then_la1
cmp #0
beq b3_from_b2
beq b4
//SEG93 [40] phi from scroll_bit::@2 to scroll_bit::@5 [phi:scroll_bit::@2->scroll_bit::@5]
//SEG94 scroll_bit::@5
//SEG95 [41] phi from scroll_bit::@5 to scroll_bit::@3 [phi:scroll_bit::@5->scroll_bit::@3]
@ -12596,7 +12965,7 @@ scroll_bit: {
lda #$80+' '
jmp b3
//SEG97 [41] phi from scroll_bit::@2 to scroll_bit::@3 [phi:scroll_bit::@2->scroll_bit::@3]
b3_from_b2:
b4:
//SEG98 [41] phi (byte) scroll_bit::b#2 = (byte) ' ' [phi:scroll_bit::@2->scroll_bit::@3#0] -- aby=coby1
lda #' '
//SEG99 scroll_bit::@3