1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-08-03 01:29:04 +00:00

Closes #59 Better ASM static value analysis. Analysis is string-based, so a more advanced method might yield better results - ef ever needed.

This commit is contained in:
jespergravgaard 2017-11-14 00:02:31 +01:00
parent 148f9ae072
commit f28db3067b
12 changed files with 85 additions and 44 deletions

View File

@ -107,6 +107,22 @@ public class AsmProgramStaticRegisterValues {
if (instructionType.getMnemnonic().equals("sty") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) { if (instructionType.getMnemnonic().equals("sty") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) {
current.setyMem(instruction.getParameter()); current.setyMem(instruction.getParameter());
} }
if (instructionType.getMnemnonic().equals("txa")) {
current.setA(current.getX());
current.setaMem(current.getxMem());
}
if (instructionType.getMnemnonic().equals("tax")) {
current.setX(current.getA());
current.setxMem(current.getaMem());
}
if (instructionType.getMnemnonic().equals("tya")) {
current.setA(current.getY());
current.setaMem(current.getyMem());
}
if (instructionType.getMnemnonic().equals("tay")) {
current.setY(current.getA());
current.setyMem(current.getaMem());
}
if (instructionType.getMnemnonic().equals("sec")) { if (instructionType.getMnemnonic().equals("sec")) {
current.setC(Boolean.TRUE); current.setC(Boolean.TRUE);
} }

View File

@ -36,6 +36,14 @@ public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization {
AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction);
if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) { if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) {
modified = remove(lineIt); modified = remove(lineIt);
} else if (instructionValues.getX() != null && instructionValues.getX().equals(immValue)) {
getLog().append("Replacing instruction "+instruction+" with TXA");
instruction.setType(AsmInstructionSet.getInstructionType("txa", AsmAddressingMode.NON, null, false));
instruction.setParameter(null);
} else if (instructionValues.getY() != null && instructionValues.getY().equals(immValue)) {
getLog().append("Replacing instruction "+instruction+" with TYA");
instruction.setType(AsmInstructionSet.getInstructionType("tya", AsmAddressingMode.NON, null, false));
instruction.setParameter(null);
} }
} }
if (instructionType.getMnemnonic().equals("lda") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) { if (instructionType.getMnemnonic().equals("lda") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) {
@ -58,6 +66,10 @@ public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization {
AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction);
if (instructionValues.getX() != null && instructionValues.getX().equals(immValue)) { if (instructionValues.getX() != null && instructionValues.getX().equals(immValue)) {
modified = remove(lineIt); modified = remove(lineIt);
} else if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) {
getLog().append("Replacing instruction "+instruction+" with TAX");
instruction.setType(AsmInstructionSet.getInstructionType("tax", AsmAddressingMode.NON, null, false));
instruction.setParameter(null);
} }
} }
if (instructionType.getMnemnonic().equals("ldx") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) { if (instructionType.getMnemnonic().equals("ldx") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) {
@ -76,6 +88,10 @@ public class Pass5UnnecesaryLoadElimination extends Pass5AsmOptimization {
AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction); AsmProgramStaticRegisterValues.AsmRegisterValues instructionValues = staticValues.getValues(instruction);
if (instructionValues.getY() != null && instructionValues.getY().equals(immValue)) { if (instructionValues.getY() != null && instructionValues.getY().equals(immValue)) {
modified = remove(lineIt); modified = remove(lineIt);
} else if (instructionValues.getA() != null && instructionValues.getA().equals(immValue)) {
getLog().append("Replacing instruction "+instruction+" with TAY");
instruction.setType(AsmInstructionSet.getInstructionType("tay", AsmAddressingMode.NON, null, false));
instruction.setParameter(null);
} }
} }
if (instructionType.getMnemnonic().equals("ldy") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) { if (instructionType.getMnemnonic().equals("ldy") && (instructionType.getAddressingMode().equals(AsmAddressingMode.ZP)||instructionType.getAddressingMode().equals(AsmAddressingMode.ABS))) {

View File

@ -395,7 +395,7 @@ init_plot_tables: {
lda #0 lda #0
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
ldx #0 tax
b3: b3:
txa txa
and #7 and #7
@ -433,7 +433,7 @@ init_screen: {
sta b+1 sta b+1
b1: b1:
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
inc b inc b
bne !+ bne !+

View File

@ -18346,6 +18346,8 @@ Removing instruction lda yd
Removing instruction lda yd Removing instruction lda yd
Removing instruction ldy #0 Removing instruction ldy #0
Removing instruction lda #0 Removing instruction lda #0
Replacing instruction ldx #0 with TAX
Replacing instruction lda #0 with TYA
Succesful ASM optimization Pass5UnnecesaryLoadElimination Succesful ASM optimization Pass5UnnecesaryLoadElimination
ASSEMBLER ASSEMBLER
//SEG0 Basic Upstart //SEG0 Basic Upstart
@ -19138,7 +19140,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
b3_from_b4: b3_from_b4:
@ -19217,7 +19219,7 @@ init_screen: {
b1: b1:
//SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -20080,7 +20082,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
@ -20154,7 +20156,7 @@ init_screen: {
b1: b1:
//SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -20978,7 +20980,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
@ -21049,7 +21051,7 @@ init_screen: {
b1: b1:
//SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -21825,7 +21827,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
//SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
//SEG320 [171] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy //SEG320 [171] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy
@ -21894,7 +21896,7 @@ init_screen: {
b1: b1:
//SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -23017,7 +23019,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG317 [171] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
//SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG318 [171] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG319 [171] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
//SEG320 [171] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy //SEG320 [171] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy
@ -23086,7 +23088,7 @@ init_screen: {
b1: b1:
//SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG348 [187] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG349 [188] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b

View File

@ -122,7 +122,7 @@ init_plot_tables: {
lda #0 lda #0
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
ldx #0 tax
b3: b3:
txa txa
and #7 and #7
@ -160,7 +160,7 @@ init_screen: {
sta b+1 sta b+1
b1: b1:
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
inc b inc b
bne !+ bne !+

View File

@ -6913,6 +6913,8 @@ init_screen: {
Removing instruction lda #0 Removing instruction lda #0
Removing instruction ldy #0 Removing instruction ldy #0
Removing instruction lda #0 Removing instruction lda #0
Replacing instruction ldx #0 with TAX
Replacing instruction lda #0 with TYA
Succesful ASM optimization Pass5UnnecesaryLoadElimination Succesful ASM optimization Pass5UnnecesaryLoadElimination
ASSEMBLER ASSEMBLER
//SEG0 Basic Upstart //SEG0 Basic Upstart
@ -7141,7 +7143,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
b3_from_b4: b3_from_b4:
@ -7220,7 +7222,7 @@ init_screen: {
b1: b1:
//SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -7511,7 +7513,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
@ -7585,7 +7587,7 @@ init_screen: {
b1: b1:
//SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -7862,7 +7864,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
jmp b3 jmp b3
//SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
@ -7933,7 +7935,7 @@ init_screen: {
b1: b1:
//SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -8191,7 +8193,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
//SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
//SEG82 [47] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy //SEG82 [47] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy
@ -8260,7 +8262,7 @@ init_screen: {
b1: b1:
//SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b
@ -8659,7 +8661,7 @@ init_plot_tables: {
sta yoffs sta yoffs
sta yoffs+1 sta yoffs+1
//SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1 //SEG79 [47] phi (byte) init_plot_tables::y#2 = (byte) 0 [phi:init_plot_tables::@2->init_plot_tables::@3#1] -- xby=coby1
ldx #0 tax
//SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3] //SEG80 [47] phi from init_plot_tables::@4 to init_plot_tables::@3 [phi:init_plot_tables::@4->init_plot_tables::@3]
//SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy //SEG81 [47] phi (byte*) init_plot_tables::yoffs#2 = (byte*) init_plot_tables::yoffs#4 [phi:init_plot_tables::@4->init_plot_tables::@3#0] -- register_copy
//SEG82 [47] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy //SEG82 [47] phi (byte) init_plot_tables::y#2 = (byte) init_plot_tables::y#1 [phi:init_plot_tables::@4->init_plot_tables::@3#1] -- register_copy
@ -8728,7 +8730,7 @@ init_screen: {
b1: b1:
//SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1 //SEG110 [63] *((byte*) init_screen::b#2) ← (byte) 0 [ init_screen::b#2 ] ( main:0::init_screen:5 [ init_screen::b#2 ] ) -- _deref_zpptrby1=coby1
ldy #0 ldy #0
lda #0 tya
sta (b),y sta (b),y
//SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1 //SEG111 [64] (byte*) init_screen::b#1 ← ++ (byte*) init_screen::b#2 [ init_screen::b#1 ] ( main:0::init_screen:5 [ init_screen::b#1 ] ) -- zpptrby1=_inc_zpptrby1
inc b inc b

View File

@ -14,10 +14,10 @@ main: {
lda #0 lda #0
sta y sta y
ldy #yd/2 ldy #yd/2
ldx #0 tax
lda #0+0*$28 lda #0+0*$28
sta idx sta idx
lda #0 txa
sta idx+1 sta idx+1
b1: b1:
lda #<screen lda #<screen

View File

@ -1764,6 +1764,8 @@ main: {
rts rts
} }
Replacing instruction ldx #0 with TAX
Replacing instruction lda #0 with TXA
Replacing label b2_from_b1 with b2 Replacing label b2_from_b1 with b2
Replacing label b1_from_b2 with b1 Replacing label b1_from_b2 with b1
Removing instruction bbegin: Removing instruction bbegin:
@ -1804,11 +1806,11 @@ main: {
//SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1 //SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1
ldy #yd/2 ldy #yd/2
//SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1 //SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1
ldx #0 tax
//SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1 //SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1
lda #0+0*$28 lda #0+0*$28
sta idx sta idx
lda #0 txa
sta idx+1 sta idx+1
jmp b1 jmp b1
//SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1] //SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
@ -1911,11 +1913,11 @@ main: {
//SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1 //SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1
ldy #yd/2 ldy #yd/2
//SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1 //SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1
ldx #0 tax
//SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1 //SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1
lda #0+0*$28 lda #0+0*$28
sta idx sta idx
lda #0 txa
sta idx+1 sta idx+1
jmp b1 jmp b1
//SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1] //SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
@ -2012,11 +2014,11 @@ main: {
//SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1 //SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1
ldy #yd/2 ldy #yd/2
//SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1 //SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1
ldx #0 tax
//SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1 //SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1
lda #0+0*$28 lda #0+0*$28
sta idx sta idx
lda #0 txa
sta idx+1 sta idx+1
//SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1] //SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
//SEG14 [2] phi (byte) main::y#2 = (byte) main::y#4 [phi:main::@2->main::@1#0] -- register_copy //SEG14 [2] phi (byte) main::y#2 = (byte) main::y#4 [phi:main::@2->main::@1#0] -- register_copy
@ -2156,11 +2158,11 @@ main: {
//SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1 //SEG10 [2] phi (byte) main::e#3 = (const byte) main::yd#0/(byte) 2 [phi:main->main::@1#1] -- yby=coby1
ldy #yd/2 ldy #yd/2
//SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1 //SEG11 [2] phi (byte) main::x#2 = (byte) 0 [phi:main->main::@1#2] -- xby=coby1
ldx #0 tax
//SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1 //SEG12 [2] phi (word) main::idx#3 = (byte) 0+(byte) 0*(byte) 40 [phi:main->main::@1#3] -- zpwo1=coby1
lda #0+0*$28 lda #0+0*$28
sta idx sta idx
lda #0 txa
sta idx+1 sta idx+1
//SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1] //SEG13 [2] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
//SEG14 [2] phi (byte) main::y#2 = (byte) main::y#4 [phi:main::@2->main::@1#0] -- register_copy //SEG14 [2] phi (byte) main::y#2 = (byte) main::y#4 [phi:main::@2->main::@1#0] -- register_copy

View File

@ -7,8 +7,8 @@
main: { main: {
lda #0 lda #0
sta cnt3 sta cnt3
ldy #0 tay
ldx #0 tax
jsr inccnt jsr inccnt
sta SCREEN+0 sta SCREEN+0
inx inx

View File

@ -1150,6 +1150,8 @@ inccnt: {
rts rts
} }
Replacing instruction ldy #0 with TAY
Replacing instruction ldx #0 with TAX
Removing instruction bbegin: Removing instruction bbegin:
Removing instruction main_from_b2: Removing instruction main_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination Succesful ASM optimization Pass5RedundantLabelElimination
@ -1178,9 +1180,9 @@ main: {
lda #0 lda #0
sta cnt3 sta cnt3
//SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1 //SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1
ldy #0 tay
//SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1 //SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1
ldx #0 tax
jsr inccnt jsr inccnt
//SEG13 main::@1 //SEG13 main::@1
b1: b1:
@ -1255,9 +1257,9 @@ main: {
lda #0 lda #0
sta cnt3 sta cnt3
//SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1 //SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1
ldy #0 tay
//SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1 //SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1
ldx #0 tax
jsr inccnt jsr inccnt
//SEG13 main::@1 //SEG13 main::@1
//SEG14 [3] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ( main:0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ) //SEG14 [3] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ( main:0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] )
@ -1353,9 +1355,9 @@ main: {
lda #0 lda #0
sta cnt3 sta cnt3
//SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1 //SEG11 [10] phi (byte) cnt2#10 = (byte) 0 [phi:main->inccnt#1] -- yby=coby1
ldy #0 tay
//SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1 //SEG12 [10] phi (byte) cnt#11 = (byte) 0 [phi:main->inccnt#2] -- xby=coby1
ldx #0 tax
jsr inccnt jsr inccnt
//SEG13 main::@1 //SEG13 main::@1
//SEG14 [3] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ( main:0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ) //SEG14 [3] (byte~) main::$0 ← (byte) inccnt::return#0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] ( main:0 [ main::$0 cnt#1 cnt2#1 cnt3#1 ] )

View File

@ -73,7 +73,7 @@ lvalue: {
sta SCREEN sta SCREEN
lda #2 lda #2
sta SCREEN+1 sta SCREEN+1
ldx #2 tax
b1: b1:
cpx #$a cpx #$a
bcc b2 bcc b2

View File

@ -3054,6 +3054,7 @@ lvalue: {
jmp b1 jmp b1
} }
Replacing instruction ldx #2 with TAX
FINAL SYMBOL TABLE FINAL SYMBOL TABLE
(label) @5 (label) @5
(label) @begin (label) @begin
@ -3264,7 +3265,7 @@ lvalue: {
sta SCREEN+1 sta SCREEN+1
//SEG66 [30] phi from lvalue to lvalue::@1 [phi:lvalue->lvalue::@1] //SEG66 [30] phi from lvalue to lvalue::@1 [phi:lvalue->lvalue::@1]
//SEG67 [30] phi (byte) lvalue::i#2 = (byte) 2 [phi:lvalue->lvalue::@1#0] -- xby=coby1 //SEG67 [30] phi (byte) lvalue::i#2 = (byte) 2 [phi:lvalue->lvalue::@1#0] -- xby=coby1
ldx #2 tax
//SEG68 lvalue::@1 //SEG68 lvalue::@1
b1: b1:
//SEG69 [31] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] ( main:0::lvalue:2 [ lvalue::i#2 ] ) -- xby_lt_coby1_then_la1 //SEG69 [31] if((byte) lvalue::i#2<(byte) 10) goto lvalue::@2 [ lvalue::i#2 ] ( main:0::lvalue:2 [ lvalue::i#2 ] ) -- xby_lt_coby1_then_la1