From dc76b2bed0b78df4004bde9a057f98e08c34d392 Mon Sep 17 00:00:00 2001 From: Jesper Gravgaard Date: Sat, 16 Mar 2019 17:54:38 +0100 Subject: [PATCH] Added a lot of signed word and boolean fragments from Travis Fisher. --- .../fragment/_deref_pwsc1=_deref_pwsc2.asm | 4 + ...vbuaa=pwsc1_derefidx_vbuaa_minus_vbuxx.asm | 9 + ...vbuaa=pwsc1_derefidx_vbuaa_minus_vbuyy.asm | 9 + ...vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa.asm | 9 + ...vbuxx=pwsc1_derefidx_vbuxx_minus_vbuz1.asm | 6 +- .../fragment/pwuc1_derefidx_vbuxx=vwuc2.asm | 4 + .../fragment/pwuc1_derefidx_vbuyy=vwuc2.asm | 4 + .../vboaa=pbuc1_derefidx_vbuxx_eq_vbuaa.asm | 5 + .../vboaa=pbuc1_derefidx_vbuxx_neq_vbuaa.asm | 4 + .../vboaa=pbuc1_derefidx_vbuyy_eq_vbuaa.asm | 5 + .../vboaa=pbuc1_derefidx_vbuyy_neq_vbuaa.asm | 4 + src/main/fragment/vboaa=vbuaa_neq_vbuc1.asm | 2 +- src/main/fragment/vboaa=vbuxx_neq_vbuc1.asm | 1 + src/main/fragment/vboaa=vbuyy_neq_vbuc1.asm | 1 + .../fragment/vbuxx=pbuc1_derefidx_vbuyy.asm | 1 + src/main/fragment/vwsz1=vwsz1_minus_vbuaa.asm | 7 + src/main/fragment/vwsz1=vwsz1_minus_vbuc1.asm | 7 + .../dk/camelot64/kickc/test/TestPrograms.java | 12 + src/test/kc/const-signed-promotion.kc | 11 + src/test/kc/signed-indexed-subtract.kc | 25 + src/test/ref/signed-indexed-subtract.asm | 171 ++ src/test/ref/signed-indexed-subtract.cfg | 140 + src/test/ref/signed-indexed-subtract.log | 2328 +++++++++++++++++ src/test/ref/signed-indexed-subtract.sym | 99 + 24 files changed, 2864 insertions(+), 4 deletions(-) create mode 100644 src/main/fragment/_deref_pwsc1=_deref_pwsc2.asm create mode 100644 src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuxx.asm create mode 100644 src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuyy.asm create mode 100644 src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa.asm create mode 100644 src/main/fragment/pwuc1_derefidx_vbuxx=vwuc2.asm create mode 100644 src/main/fragment/pwuc1_derefidx_vbuyy=vwuc2.asm create mode 100644 src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_eq_vbuaa.asm create mode 100644 src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_neq_vbuaa.asm create mode 100644 src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_eq_vbuaa.asm create mode 100644 src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_neq_vbuaa.asm create mode 100644 src/main/fragment/vbuxx=pbuc1_derefidx_vbuyy.asm create mode 100644 src/main/fragment/vwsz1=vwsz1_minus_vbuaa.asm create mode 100644 src/main/fragment/vwsz1=vwsz1_minus_vbuc1.asm create mode 100644 src/test/kc/const-signed-promotion.kc create mode 100644 src/test/kc/signed-indexed-subtract.kc create mode 100644 src/test/ref/signed-indexed-subtract.asm create mode 100644 src/test/ref/signed-indexed-subtract.cfg create mode 100644 src/test/ref/signed-indexed-subtract.log create mode 100644 src/test/ref/signed-indexed-subtract.sym diff --git a/src/main/fragment/_deref_pwsc1=_deref_pwsc2.asm b/src/main/fragment/_deref_pwsc1=_deref_pwsc2.asm new file mode 100644 index 000000000..6db8608c3 --- /dev/null +++ b/src/main/fragment/_deref_pwsc1=_deref_pwsc2.asm @@ -0,0 +1,4 @@ +lda {c2} +sta {c1} +lda {c2}+1 +sta {c1}+1 \ No newline at end of file diff --git a/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuxx.asm b/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuxx.asm new file mode 100644 index 000000000..52d8b6a00 --- /dev/null +++ b/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuxx.asm @@ -0,0 +1,9 @@ +sec +stx $ff +tax +lda {c1},x +sbc $ff +sta {c1},x +bcs !+ +dec {c1}+1,x +!: \ No newline at end of file diff --git a/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuyy.asm b/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuyy.asm new file mode 100644 index 000000000..81a2fe012 --- /dev/null +++ b/src/main/fragment/pwsc1_derefidx_vbuaa=pwsc1_derefidx_vbuaa_minus_vbuyy.asm @@ -0,0 +1,9 @@ +sec +sty $ff +tay +lda {c1},y +sbc $ff +sta {c1},y +lda {c1}+1,y +sbc #$00 +sta {c1}+1,y diff --git a/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa.asm b/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa.asm new file mode 100644 index 000000000..bdfd99612 --- /dev/null +++ b/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa.asm @@ -0,0 +1,9 @@ +clc +sbc {c1},x +eor #$ff +sta {c1},x +bcc !+ +lda {c1}+1,x +sbc #$01 +sta {c1}+1,x +!: \ No newline at end of file diff --git a/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuz1.asm b/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuz1.asm index 971c9734e..1b68e4ece 100644 --- a/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuz1.asm +++ b/src/main/fragment/pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuz1.asm @@ -2,6 +2,6 @@ sec lda {c1},x sbc {z1} sta {c1},x -lda {c1}+1,x -sbc #0 -sta {c1}+1,x \ No newline at end of file +bcs !+ +dec {c1}+1,x +!: diff --git a/src/main/fragment/pwuc1_derefidx_vbuxx=vwuc2.asm b/src/main/fragment/pwuc1_derefidx_vbuxx=vwuc2.asm new file mode 100644 index 000000000..5d322b4cf --- /dev/null +++ b/src/main/fragment/pwuc1_derefidx_vbuxx=vwuc2.asm @@ -0,0 +1,4 @@ +lda #<{c2} +sta {c1},x +lda #>{c2} +sta {c1}+1,x diff --git a/src/main/fragment/pwuc1_derefidx_vbuyy=vwuc2.asm b/src/main/fragment/pwuc1_derefidx_vbuyy=vwuc2.asm new file mode 100644 index 000000000..3989e58e9 --- /dev/null +++ b/src/main/fragment/pwuc1_derefidx_vbuyy=vwuc2.asm @@ -0,0 +1,4 @@ +lda #<{c2} +sta {c1},y +lda #>{c2} +sta {c1}+1,y diff --git a/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_eq_vbuaa.asm b/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_eq_vbuaa.asm new file mode 100644 index 000000000..40f5a10b6 --- /dev/null +++ b/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_eq_vbuaa.asm @@ -0,0 +1,5 @@ +eor {c1},x +beq !+ +lda #1 +!: +eor #1 \ No newline at end of file diff --git a/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_neq_vbuaa.asm b/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_neq_vbuaa.asm new file mode 100644 index 000000000..5091425de --- /dev/null +++ b/src/main/fragment/vboaa=pbuc1_derefidx_vbuxx_neq_vbuaa.asm @@ -0,0 +1,4 @@ +eor {c1},x +beq !+ +lda #1 +!: diff --git a/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_eq_vbuaa.asm b/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_eq_vbuaa.asm new file mode 100644 index 000000000..44a8256c5 --- /dev/null +++ b/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_eq_vbuaa.asm @@ -0,0 +1,5 @@ +eor {c1},y +beq !+ +lda #1 +!: +eor #1 \ No newline at end of file diff --git a/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_neq_vbuaa.asm b/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_neq_vbuaa.asm new file mode 100644 index 000000000..5d3c9dcff --- /dev/null +++ b/src/main/fragment/vboaa=pbuc1_derefidx_vbuyy_neq_vbuaa.asm @@ -0,0 +1,4 @@ +eor {c1},y +beq !+ +lda #1 +!: diff --git a/src/main/fragment/vboaa=vbuaa_neq_vbuc1.asm b/src/main/fragment/vboaa=vbuaa_neq_vbuc1.asm index 9f587078f..41a3ac3e3 100644 --- a/src/main/fragment/vboaa=vbuaa_neq_vbuc1.asm +++ b/src/main/fragment/vboaa=vbuaa_neq_vbuc1.asm @@ -1,4 +1,4 @@ -cmp #{c1} +eor #{c1} beq !+ lda #1 !: \ No newline at end of file diff --git a/src/main/fragment/vboaa=vbuxx_neq_vbuc1.asm b/src/main/fragment/vboaa=vbuxx_neq_vbuc1.asm index 117f16d1e..fe070abb1 100644 --- a/src/main/fragment/vboaa=vbuxx_neq_vbuc1.asm +++ b/src/main/fragment/vboaa=vbuxx_neq_vbuc1.asm @@ -1,3 +1,4 @@ +lda #0 cpx #{c1} beq !+ lda #1 diff --git a/src/main/fragment/vboaa=vbuyy_neq_vbuc1.asm b/src/main/fragment/vboaa=vbuyy_neq_vbuc1.asm index c61308114..c3825b9a6 100644 --- a/src/main/fragment/vboaa=vbuyy_neq_vbuc1.asm +++ b/src/main/fragment/vboaa=vbuyy_neq_vbuc1.asm @@ -1,3 +1,4 @@ +lda #0 cpy #{c1} beq !+ lda #1 diff --git a/src/main/fragment/vbuxx=pbuc1_derefidx_vbuyy.asm b/src/main/fragment/vbuxx=pbuc1_derefidx_vbuyy.asm new file mode 100644 index 000000000..a05e67aae --- /dev/null +++ b/src/main/fragment/vbuxx=pbuc1_derefidx_vbuyy.asm @@ -0,0 +1 @@ +ldx {c1},y \ No newline at end of file diff --git a/src/main/fragment/vwsz1=vwsz1_minus_vbuaa.asm b/src/main/fragment/vwsz1=vwsz1_minus_vbuaa.asm new file mode 100644 index 000000000..6f6f83244 --- /dev/null +++ b/src/main/fragment/vwsz1=vwsz1_minus_vbuaa.asm @@ -0,0 +1,7 @@ +clc +sbc {z1} +eor #$ff +sta {z1} +bcc !+ +dec {z1}+1 +!: diff --git a/src/main/fragment/vwsz1=vwsz1_minus_vbuc1.asm b/src/main/fragment/vwsz1=vwsz1_minus_vbuc1.asm new file mode 100644 index 000000000..133d91476 --- /dev/null +++ b/src/main/fragment/vwsz1=vwsz1_minus_vbuc1.asm @@ -0,0 +1,7 @@ +sec +lda {z1} +sbc #{c1} +sta {z1} +bcs !+ +dec {z1}+1 +!: \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 1ad081aea..be9e0a745 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -44,6 +44,18 @@ public class TestPrograms { AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false); } + /* + @Test + public void testConstSignedPromotion() throws IOException, URISyntaxException { + compileAndCompare("const-signed-promotion"); + } + */ + + @Test + public void testSignedIndexedSubtract() throws IOException, URISyntaxException { + compileAndCompare("signed-indexed-subtract"); + } + @Test public void testInlineAsmRefScoped() throws IOException, URISyntaxException { compileAndCompare("inline-asm-ref-scoped"); diff --git a/src/test/kc/const-signed-promotion.kc b/src/test/kc/const-signed-promotion.kc new file mode 100644 index 000000000..4dfb46eb3 --- /dev/null +++ b/src/test/kc/const-signed-promotion.kc @@ -0,0 +1,11 @@ +// Test fragment promotion of a constant (400) to signed word even if it also matches an unsigned word + +signed word[3] world ; + +void main() { + for(byte i:0..2) { + world[i<<1]= 400; + } + signed word* screen = $400; + *screen = world[0]; +} \ No newline at end of file diff --git a/src/test/kc/signed-indexed-subtract.kc b/src/test/kc/signed-indexed-subtract.kc new file mode 100644 index 000000000..0ae94ab0c --- /dev/null +++ b/src/test/kc/signed-indexed-subtract.kc @@ -0,0 +1,25 @@ +// Tests that signed indexed subtract works as intended + +import "print" + +signed word[] words = {-$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000}; + +void main() { + + for(byte i: 0..8) { + byte idx = i<<1; + sub(idx, $80); + sub(idx, $40); + sub(idx, $40); + } + print_cls(); + for(byte j: 0..8) { + print_sword(words[j<<1]); + print_ln(); + } + +} + +void sub(byte idx, byte s) { + words[idx] -= s; +} \ No newline at end of file diff --git a/src/test/ref/signed-indexed-subtract.asm b/src/test/ref/signed-indexed-subtract.asm new file mode 100644 index 000000000..445e46c1e --- /dev/null +++ b/src/test/ref/signed-indexed-subtract.asm @@ -0,0 +1,171 @@ +// Tests that signed indexed subtract works as intended +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .label print_line_cursor = 2 + .label print_char_cursor = 7 +main: { + ldy #0 + b1: + tya + asl + tax + lda #$80 + jsr sub + lda #$40 + jsr sub + lda #$40 + jsr sub + iny + cpy #9 + bne b1 + jsr print_cls + lda #<$400 + sta print_line_cursor + lda #>$400 + sta print_line_cursor+1 + lda #<$400 + sta print_char_cursor + lda #>$400 + sta print_char_cursor+1 + ldx #0 + b2: + txa + asl + tay + lda words,y + sta print_sword.w + lda words+1,y + sta print_sword.w+1 + jsr print_sword + jsr print_ln + inx + cpx #9 + bne b12 + rts + b12: + lda print_line_cursor + sta print_char_cursor + lda print_line_cursor+1 + sta print_char_cursor+1 + jmp b2 +} +// Print a newline +print_ln: { + b1: + lda print_line_cursor + clc + adc #$28 + sta print_line_cursor + bcc !+ + inc print_line_cursor+1 + !: + lda print_line_cursor+1 + cmp print_char_cursor+1 + bcc b1 + bne !+ + lda print_line_cursor + cmp print_char_cursor + bcc b1 + !: + rts +} +// Print a signed word as HEX +// print_sword(signed word zeropage(4) w) +print_sword: { + .label w = 4 + lda w+1 + bpl b1 + lda #'-' + jsr print_char + sec + lda w + eor #$ff + adc #0 + sta w + lda w+1 + eor #$ff + adc #0 + sta w+1 + b1: + jsr print_word + rts +} +// Print a word as HEX +print_word: { + lda print_sword.w+1 + sta print_byte.b + jsr print_byte + lda print_sword.w + sta print_byte.b + jsr print_byte + rts +} +// Print a byte as HEX +// print_byte(byte zeropage(6) b) +print_byte: { + .label b = 6 + lda b + lsr + lsr + lsr + lsr + tay + lda print_hextab,y + jsr print_char + lda #$f + and b + tay + lda print_hextab,y + jsr print_char + rts +} +// Print a single char +// print_char(byte register(A) ch) +print_char: { + ldy #0 + sta (print_char_cursor),y + inc print_char_cursor + bne !+ + inc print_char_cursor+1 + !: + rts +} +// Clear the screen. Also resets current line/char cursor. +print_cls: { + .label sc = 2 + lda #<$400 + sta sc + lda #>$400 + sta sc+1 + b1: + lda #' ' + ldy #0 + sta (sc),y + inc sc + bne !+ + inc sc+1 + !: + lda sc+1 + cmp #>$400+$3e8 + bne b1 + lda sc + cmp #<$400+$3e8 + bne b1 + rts +} +// sub(byte register(X) idx, byte register(A) s) +sub: { + clc + sbc words,x + eor #$ff + sta words,x + bcc !+ + lda words+1,x + sbc #1 + sta words+1,x + !: + rts +} + print_hextab: .text "0123456789abcdef" + words: .word -$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000 diff --git a/src/test/ref/signed-indexed-subtract.cfg b/src/test/ref/signed-indexed-subtract.cfg new file mode 100644 index 000000000..22f958115 --- /dev/null +++ b/src/test/ref/signed-indexed-subtract.cfg @@ -0,0 +1,140 @@ +@begin: scope:[] from + [0] phi() + to:@21 +@21: scope:[] from @begin + [1] phi() + [2] call main + to:@end +@end: scope:[] from @21 + [3] phi() +main: scope:[main] from @21 + [4] phi() + to:main::@1 +main::@1: scope:[main] from main main::@7 + [5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) + [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [7] (byte) sub::idx#0 ← (byte) main::idx#0 + [8] call sub + to:main::@5 +main::@5: scope:[main] from main::@1 + [9] (byte) sub::idx#1 ← (byte) main::idx#0 + [10] call sub + to:main::@6 +main::@6: scope:[main] from main::@5 + [11] (byte) sub::idx#2 ← (byte) main::idx#0 + [12] call sub + to:main::@7 +main::@7: scope:[main] from main::@6 + [13] (byte) main::i#1 ← ++ (byte) main::i#2 + [14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 + to:main::@3 +main::@3: scope:[main] from main::@7 + [15] phi() + [16] call print_cls + to:main::@2 +main::@2: scope:[main] from main::@12 main::@3 + [17] (byte*) print_line_cursor#19 ← phi( main::@12/(byte*) print_line_cursor#1 main::@3/((byte*))(word/signed word/dword/signed dword) $400 ) + [17] (byte*) print_char_cursor#46 ← phi( main::@12/(byte*~) print_char_cursor#56 main::@3/((byte*))(word/signed word/dword/signed dword) $400 ) + [17] (byte) main::j#2 ← phi( main::@12/(byte) main::j#1 main::@3/(byte/signed byte/word/signed word/dword/signed dword) 0 ) + [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) + [20] call print_sword + to:main::@9 +main::@9: scope:[main] from main::@2 + [21] phi() + [22] call print_ln + to:main::@10 +main::@10: scope:[main] from main::@9 + [23] (byte) main::j#1 ← ++ (byte) main::j#2 + [24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12 + to:main::@return +main::@return: scope:[main] from main::@10 + [25] return + to:@return +main::@12: scope:[main] from main::@10 + [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 + to:main::@2 +print_ln: scope:[print_ln] from main::@9 + [27] phi() + to:print_ln::@1 +print_ln::@1: scope:[print_ln] from print_ln print_ln::@1 + [28] (byte*) print_line_cursor#9 ← phi( print_ln/(byte*) print_line_cursor#19 print_ln::@1/(byte*) print_line_cursor#1 ) + [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 + [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 + to:print_ln::@return +print_ln::@return: scope:[print_ln] from print_ln::@1 + [31] return + to:@return +print_sword: scope:[print_sword] from main::@2 + [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 + to:print_sword::@2 +print_sword::@2: scope:[print_sword] from print_sword + [33] phi() + [34] call print_char + to:print_sword::@4 +print_sword::@4: scope:[print_sword] from print_sword::@2 + [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 + to:print_sword::@1 +print_sword::@1: scope:[print_sword] from print_sword print_sword::@4 + [36] (byte*) print_char_cursor#41 ← phi( print_sword/(byte*) print_char_cursor#46 print_sword::@4/(byte*) print_char_cursor#12 ) + [36] (signed word) print_sword::w#3 ← phi( print_sword/(signed word) print_sword::w#1 print_sword::@4/(signed word) print_sword::w#0 ) + [37] call print_word + to:print_sword::@return +print_sword::@return: scope:[print_sword] from print_sword::@1 + [38] return + to:@return +print_word: scope:[print_word] from print_sword::@1 + [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 + [40] call print_byte + to:print_word::@1 +print_word::@1: scope:[print_word] from print_word + [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 + [42] call print_byte + to:print_word::@return +print_word::@return: scope:[print_word] from print_word::@1 + [43] return + to:@return +print_byte: scope:[print_byte] from print_word print_word::@1 + [44] (byte*) print_char_cursor#44 ← phi( print_word/(byte*) print_char_cursor#41 print_word::@1/(byte*) print_char_cursor#12 ) + [44] (byte) print_byte::b#2 ← phi( print_word/(byte) print_byte::b#0 print_word::@1/(byte) print_byte::b#1 ) + [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 + [46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) + [47] call print_char + to:print_byte::@1 +print_byte::@1: scope:[print_byte] from print_byte + [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f + [49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) + [50] call print_char + to:print_byte::@return +print_byte::@return: scope:[print_byte] from print_byte::@1 + [51] return + to:@return +print_char: scope:[print_char] from print_byte print_byte::@1 print_sword::@2 + [52] (byte*) print_char_cursor#32 ← phi( print_byte/(byte*) print_char_cursor#44 print_byte::@1/(byte*) print_char_cursor#12 print_sword::@2/(byte*) print_char_cursor#46 ) + [52] (byte) print_char::ch#3 ← phi( print_byte/(byte) print_char::ch#1 print_byte::@1/(byte) print_char::ch#2 print_sword::@2/(byte) '-' ) + [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 + [54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 + to:print_char::@return +print_char::@return: scope:[print_char] from print_char + [55] return + to:@return +print_cls: scope:[print_cls] from main::@3 + [56] phi() + to:print_cls::@1 +print_cls::@1: scope:[print_cls] from print_cls print_cls::@1 + [57] (byte*) print_cls::sc#2 ← phi( print_cls/((byte*))(word/signed word/dword/signed dword) $400 print_cls::@1/(byte*) print_cls::sc#1 ) + [58] *((byte*) print_cls::sc#2) ← (byte) ' ' + [59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 + [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 + to:print_cls::@return +print_cls::@return: scope:[print_cls] from print_cls::@1 + [61] return + to:@return +sub: scope:[sub] from main::@1 main::@5 main::@6 + [62] (byte) sub::s#3 ← phi( main::@1/(byte/word/signed word/dword/signed dword) $80 main::@5/(byte/signed byte/word/signed word/dword/signed dword) $40 main::@6/(byte/signed byte/word/signed word/dword/signed dword) $40 ) + [62] (byte) sub::idx#3 ← phi( main::@1/(byte) sub::idx#0 main::@5/(byte) sub::idx#1 main::@6/(byte) sub::idx#2 ) + [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 + to:sub::@return +sub::@return: scope:[sub] from sub + [64] return + to:@return diff --git a/src/test/ref/signed-indexed-subtract.log b/src/test/ref/signed-indexed-subtract.log new file mode 100644 index 000000000..902e73e1a --- /dev/null +++ b/src/test/ref/signed-indexed-subtract.log @@ -0,0 +1,2328 @@ + +CONTROL FLOW GRAPH SSA +@begin: scope:[] from + (byte*) print_screen#0 ← ((byte*)) (word/signed word/dword/signed dword) $400 + (byte*) print_line_cursor#0 ← (byte*) print_screen#0 + (byte*) print_char_cursor#0 ← (byte*) print_line_cursor#0 + to:@12 +print_ln: scope:[print_ln] from main::@9 + (byte*) print_char_cursor#40 ← phi( main::@9/(byte*) print_char_cursor#17 ) + (byte*) print_line_cursor#17 ← phi( main::@9/(byte*) print_line_cursor#19 ) + to:print_ln::@1 +print_ln::@1: scope:[print_ln] from print_ln print_ln::@1 + (byte*) print_char_cursor#21 ← phi( print_ln/(byte*) print_char_cursor#40 print_ln::@1/(byte*) print_char_cursor#21 ) + (byte*) print_line_cursor#9 ← phi( print_ln/(byte*) print_line_cursor#17 print_ln::@1/(byte*) print_line_cursor#1 ) + (byte*~) print_ln::$0 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 + (byte*) print_line_cursor#1 ← (byte*~) print_ln::$0 + (bool~) print_ln::$1 ← (byte*) print_line_cursor#1 < (byte*) print_char_cursor#21 + if((bool~) print_ln::$1) goto print_ln::@1 + to:print_ln::@2 +print_ln::@2: scope:[print_ln] from print_ln::@1 + (byte*) print_line_cursor#10 ← phi( print_ln::@1/(byte*) print_line_cursor#1 ) + (byte*) print_char_cursor#1 ← (byte*) print_line_cursor#10 + to:print_ln::@return +print_ln::@return: scope:[print_ln] from print_ln::@2 + (byte*) print_char_cursor#22 ← phi( print_ln::@2/(byte*) print_char_cursor#1 ) + (byte*) print_line_cursor#11 ← phi( print_ln::@2/(byte*) print_line_cursor#10 ) + (byte*) print_line_cursor#2 ← (byte*) print_line_cursor#11 + (byte*) print_char_cursor#2 ← (byte*) print_char_cursor#22 + return + to:@return +print_sword: scope:[print_sword] from main::@2 + (byte*) print_char_cursor#48 ← phi( main::@2/(byte*) print_char_cursor#46 ) + (signed word) print_sword::w#2 ← phi( main::@2/(signed word) print_sword::w#1 ) + (bool~) print_sword::$0 ← (signed word) print_sword::w#2 < (byte/signed byte/word/signed word/dword/signed dword) 0 + (bool~) print_sword::$1 ← ! (bool~) print_sword::$0 + if((bool~) print_sword::$1) goto print_sword::@1 + to:print_sword::@2 +print_sword::@1: scope:[print_sword] from print_sword print_sword::@4 + (byte*) print_char_cursor#41 ← phi( print_sword/(byte*) print_char_cursor#48 print_sword::@4/(byte*) print_char_cursor#4 ) + (signed word) print_sword::w#3 ← phi( print_sword/(signed word) print_sword::w#2 print_sword::@4/(signed word) print_sword::w#0 ) + (word~) print_sword::$4 ← ((word)) (signed word) print_sword::w#3 + (word) print_word::w#0 ← (word~) print_sword::$4 + call print_word + to:print_sword::@3 +print_sword::@3: scope:[print_sword] from print_sword::@1 + (byte*) print_char_cursor#23 ← phi( print_sword::@1/(byte*) print_char_cursor#8 ) + (byte*) print_char_cursor#3 ← (byte*) print_char_cursor#23 + to:print_sword::@return +print_sword::@2: scope:[print_sword] from print_sword + (signed word) print_sword::w#5 ← phi( print_sword/(signed word) print_sword::w#2 ) + (byte*) print_char_cursor#42 ← phi( print_sword/(byte*) print_char_cursor#48 ) + (byte) print_char::ch#0 ← (byte) '-' + call print_char + to:print_sword::@4 +print_sword::@4: scope:[print_sword] from print_sword::@2 + (signed word) print_sword::w#4 ← phi( print_sword::@2/(signed word) print_sword::w#5 ) + (byte*) print_char_cursor#24 ← phi( print_sword::@2/(byte*) print_char_cursor#13 ) + (byte*) print_char_cursor#4 ← (byte*) print_char_cursor#24 + (signed word~) print_sword::$3 ← - (signed word) print_sword::w#4 + (signed word) print_sword::w#0 ← (signed word~) print_sword::$3 + to:print_sword::@1 +print_sword::@return: scope:[print_sword] from print_sword::@3 + (byte*) print_char_cursor#25 ← phi( print_sword::@3/(byte*) print_char_cursor#3 ) + (byte*) print_char_cursor#5 ← (byte*) print_char_cursor#25 + return + to:@return +print_word: scope:[print_word] from print_sword::@1 + (byte*) print_char_cursor#43 ← phi( print_sword::@1/(byte*) print_char_cursor#41 ) + (word) print_word::w#1 ← phi( print_sword::@1/(word) print_word::w#0 ) + (byte~) print_word::$0 ← > (word) print_word::w#1 + (byte) print_byte::b#0 ← (byte~) print_word::$0 + call print_byte + to:print_word::@1 +print_word::@1: scope:[print_word] from print_word + (word) print_word::w#2 ← phi( print_word/(word) print_word::w#1 ) + (byte*) print_char_cursor#26 ← phi( print_word/(byte*) print_char_cursor#11 ) + (byte*) print_char_cursor#6 ← (byte*) print_char_cursor#26 + (byte~) print_word::$2 ← < (word) print_word::w#2 + (byte) print_byte::b#1 ← (byte~) print_word::$2 + call print_byte + to:print_word::@2 +print_word::@2: scope:[print_word] from print_word::@1 + (byte*) print_char_cursor#27 ← phi( print_word::@1/(byte*) print_char_cursor#11 ) + (byte*) print_char_cursor#7 ← (byte*) print_char_cursor#27 + to:print_word::@return +print_word::@return: scope:[print_word] from print_word::@2 + (byte*) print_char_cursor#28 ← phi( print_word::@2/(byte*) print_char_cursor#7 ) + (byte*) print_char_cursor#8 ← (byte*) print_char_cursor#28 + return + to:@return +@12: scope:[] from @begin + (byte*) print_screen#12 ← phi( @begin/(byte*) print_screen#0 ) + (byte*) print_char_cursor#51 ← phi( @begin/(byte*) print_char_cursor#0 ) + (byte*) print_line_cursor#24 ← phi( @begin/(byte*) print_line_cursor#0 ) + (byte[]) print_hextab#0 ← (const string) $4 + to:@19 +print_byte: scope:[print_byte] from print_word print_word::@1 + (byte*) print_char_cursor#44 ← phi( print_word/(byte*) print_char_cursor#43 print_word::@1/(byte*) print_char_cursor#6 ) + (byte) print_byte::b#2 ← phi( print_word/(byte) print_byte::b#0 print_word::@1/(byte) print_byte::b#1 ) + (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 + (byte) print_char::ch#1 ← *((byte[]) print_hextab#0 + (byte~) print_byte::$0) + call print_char + to:print_byte::@1 +print_byte::@1: scope:[print_byte] from print_byte + (byte) print_byte::b#3 ← phi( print_byte/(byte) print_byte::b#2 ) + (byte*) print_char_cursor#29 ← phi( print_byte/(byte*) print_char_cursor#13 ) + (byte*) print_char_cursor#9 ← (byte*) print_char_cursor#29 + (byte~) print_byte::$2 ← (byte) print_byte::b#3 & (byte/signed byte/word/signed word/dword/signed dword) $f + (byte) print_char::ch#2 ← *((byte[]) print_hextab#0 + (byte~) print_byte::$2) + call print_char + to:print_byte::@2 +print_byte::@2: scope:[print_byte] from print_byte::@1 + (byte*) print_char_cursor#30 ← phi( print_byte::@1/(byte*) print_char_cursor#13 ) + (byte*) print_char_cursor#10 ← (byte*) print_char_cursor#30 + to:print_byte::@return +print_byte::@return: scope:[print_byte] from print_byte::@2 + (byte*) print_char_cursor#31 ← phi( print_byte::@2/(byte*) print_char_cursor#10 ) + (byte*) print_char_cursor#11 ← (byte*) print_char_cursor#31 + return + to:@return +print_char: scope:[print_char] from print_byte print_byte::@1 print_sword::@2 + (byte*) print_char_cursor#32 ← phi( print_byte/(byte*) print_char_cursor#44 print_byte::@1/(byte*) print_char_cursor#9 print_sword::@2/(byte*) print_char_cursor#42 ) + (byte) print_char::ch#3 ← phi( print_byte/(byte) print_char::ch#1 print_byte::@1/(byte) print_char::ch#2 print_sword::@2/(byte) print_char::ch#0 ) + *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 + (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 + to:print_char::@return +print_char::@return: scope:[print_char] from print_char + (byte*) print_char_cursor#33 ← phi( print_char/(byte*) print_char_cursor#12 ) + (byte*) print_char_cursor#13 ← (byte*) print_char_cursor#33 + return + to:@return +print_cls: scope:[print_cls] from main::@3 + (byte*) print_screen#1 ← phi( main::@3/(byte*) print_screen#4 ) + (byte*) print_cls::sc#0 ← (byte*) print_screen#1 + to:print_cls::@1 +print_cls::@1: scope:[print_cls] from print_cls print_cls::@1 + (byte*) print_screen#2 ← phi( print_cls/(byte*) print_screen#1 print_cls::@1/(byte*) print_screen#2 ) + (byte*) print_cls::sc#2 ← phi( print_cls/(byte*) print_cls::sc#0 print_cls::@1/(byte*) print_cls::sc#1 ) + *((byte*) print_cls::sc#2) ← (byte) ' ' + (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 + (byte*~) print_cls::$0 ← (byte*) print_screen#2 + (word/signed word/dword/signed dword) $3e8 + (bool~) print_cls::$1 ← (byte*) print_cls::sc#1 != (byte*~) print_cls::$0 + if((bool~) print_cls::$1) goto print_cls::@1 + to:print_cls::@2 +print_cls::@2: scope:[print_cls] from print_cls::@1 + (byte*) print_screen#3 ← phi( print_cls::@1/(byte*) print_screen#2 ) + (byte*) print_line_cursor#3 ← (byte*) print_screen#3 + (byte*) print_char_cursor#14 ← (byte*) print_line_cursor#3 + to:print_cls::@return +print_cls::@return: scope:[print_cls] from print_cls::@2 + (byte*) print_char_cursor#34 ← phi( print_cls::@2/(byte*) print_char_cursor#14 ) + (byte*) print_line_cursor#12 ← phi( print_cls::@2/(byte*) print_line_cursor#3 ) + (byte*) print_line_cursor#4 ← (byte*) print_line_cursor#12 + (byte*) print_char_cursor#15 ← (byte*) print_char_cursor#34 + return + to:@return +@19: scope:[] from @12 + (byte*) print_screen#11 ← phi( @12/(byte*) print_screen#12 ) + (byte*) print_char_cursor#50 ← phi( @12/(byte*) print_char_cursor#51 ) + (byte*) print_line_cursor#23 ← phi( @12/(byte*) print_line_cursor#24 ) + (signed word/signed dword~) $0 ← - (word/signed word/dword/signed dword) $6000 + (signed word/signed dword~) $1 ← - (word/signed word/dword/signed dword) $600 + (signed byte/signed word/signed dword~) $2 ← - (byte/signed byte/word/signed word/dword/signed dword) $60 + (signed byte/signed word/signed dword~) $3 ← - (byte/signed byte/word/signed word/dword/signed dword) 6 + (signed word[]) words#0 ← { (signed word/signed dword~) $0, (signed word/signed dword~) $1, (signed byte/signed word/signed dword~) $2, (signed byte/signed word/signed dword~) $3, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) $60, (word/signed word/dword/signed dword) $600, (word/signed word/dword/signed dword) $6000 } + to:@21 +main: scope:[main] from @21 + (byte*) print_char_cursor#55 ← phi( @21/(byte*) print_char_cursor#47 ) + (byte*) print_line_cursor#28 ← phi( @21/(byte*) print_line_cursor#20 ) + (byte*) print_screen#9 ← phi( @21/(byte*) print_screen#10 ) + (byte) main::i#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 + to:main::@1 +main::@1: scope:[main] from main main::@7 + (byte*) print_char_cursor#54 ← phi( main/(byte*) print_char_cursor#55 main::@7/(byte*) print_char_cursor#49 ) + (byte*) print_line_cursor#27 ← phi( main/(byte*) print_line_cursor#28 main::@7/(byte*) print_line_cursor#21 ) + (byte*) print_screen#8 ← phi( main/(byte*) print_screen#9 main::@7/(byte*) print_screen#5 ) + (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@7/(byte) main::i#1 ) + (byte~) main::$0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + (byte) main::idx#0 ← (byte~) main::$0 + (byte) sub::idx#0 ← (byte) main::idx#0 + (byte) sub::s#0 ← (byte/word/signed word/dword/signed dword) $80 + call sub + to:main::@5 +main::@5: scope:[main] from main::@1 + (byte*) print_char_cursor#53 ← phi( main::@1/(byte*) print_char_cursor#54 ) + (byte*) print_line_cursor#26 ← phi( main::@1/(byte*) print_line_cursor#27 ) + (byte*) print_screen#7 ← phi( main::@1/(byte*) print_screen#8 ) + (byte) main::i#5 ← phi( main::@1/(byte) main::i#2 ) + (byte) main::idx#1 ← phi( main::@1/(byte) main::idx#0 ) + (byte) sub::idx#1 ← (byte) main::idx#1 + (byte) sub::s#1 ← (byte/signed byte/word/signed word/dword/signed dword) $40 + call sub + to:main::@6 +main::@6: scope:[main] from main::@5 + (byte*) print_char_cursor#52 ← phi( main::@5/(byte*) print_char_cursor#53 ) + (byte*) print_line_cursor#25 ← phi( main::@5/(byte*) print_line_cursor#26 ) + (byte*) print_screen#6 ← phi( main::@5/(byte*) print_screen#7 ) + (byte) main::i#4 ← phi( main::@5/(byte) main::i#5 ) + (byte) main::idx#2 ← phi( main::@5/(byte) main::idx#1 ) + (byte) sub::idx#2 ← (byte) main::idx#2 + (byte) sub::s#2 ← (byte/signed byte/word/signed word/dword/signed dword) $40 + call sub + to:main::@7 +main::@7: scope:[main] from main::@6 + (byte*) print_char_cursor#49 ← phi( main::@6/(byte*) print_char_cursor#52 ) + (byte*) print_line_cursor#21 ← phi( main::@6/(byte*) print_line_cursor#25 ) + (byte*) print_screen#5 ← phi( main::@6/(byte*) print_screen#6 ) + (byte) main::i#3 ← phi( main::@6/(byte) main::i#4 ) + (byte) main::i#1 ← (byte) main::i#3 + rangenext(0,8) + (bool~) main::$4 ← (byte) main::i#1 != rangelast(0,8) + if((bool~) main::$4) goto main::@1 + to:main::@3 +main::@3: scope:[main] from main::@7 + (byte*) print_char_cursor#45 ← phi( main::@7/(byte*) print_char_cursor#49 ) + (byte*) print_line_cursor#18 ← phi( main::@7/(byte*) print_line_cursor#21 ) + (byte*) print_screen#4 ← phi( main::@7/(byte*) print_screen#5 ) + call print_cls + to:main::@8 +main::@8: scope:[main] from main::@3 + (byte*) print_char_cursor#35 ← phi( main::@3/(byte*) print_char_cursor#15 ) + (byte*) print_line_cursor#13 ← phi( main::@3/(byte*) print_line_cursor#4 ) + (byte*) print_line_cursor#5 ← (byte*) print_line_cursor#13 + (byte*) print_char_cursor#16 ← (byte*) print_char_cursor#35 + (byte) main::j#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0 + to:main::@2 +main::@2: scope:[main] from main::@10 main::@8 + (byte*) print_line_cursor#22 ← phi( main::@10/(byte*) print_line_cursor#6 main::@8/(byte*) print_line_cursor#5 ) + (byte*) print_char_cursor#46 ← phi( main::@10/(byte*) print_char_cursor#18 main::@8/(byte*) print_char_cursor#16 ) + (byte) main::j#2 ← phi( main::@10/(byte) main::j#1 main::@8/(byte) main::j#0 ) + (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + (signed word) print_sword::w#1 ← *((signed word[]) words#0 + (byte~) main::$6) + call print_sword + to:main::@9 +main::@9: scope:[main] from main::@2 + (byte) main::j#4 ← phi( main::@2/(byte) main::j#2 ) + (byte*) print_line_cursor#19 ← phi( main::@2/(byte*) print_line_cursor#22 ) + (byte*) print_char_cursor#36 ← phi( main::@2/(byte*) print_char_cursor#5 ) + (byte*) print_char_cursor#17 ← (byte*) print_char_cursor#36 + call print_ln + to:main::@10 +main::@10: scope:[main] from main::@9 + (byte) main::j#3 ← phi( main::@9/(byte) main::j#4 ) + (byte*) print_char_cursor#37 ← phi( main::@9/(byte*) print_char_cursor#2 ) + (byte*) print_line_cursor#14 ← phi( main::@9/(byte*) print_line_cursor#2 ) + (byte*) print_line_cursor#6 ← (byte*) print_line_cursor#14 + (byte*) print_char_cursor#18 ← (byte*) print_char_cursor#37 + (byte) main::j#1 ← (byte) main::j#3 + rangenext(0,8) + (bool~) main::$9 ← (byte) main::j#1 != rangelast(0,8) + if((bool~) main::$9) goto main::@2 + to:main::@return +main::@return: scope:[main] from main::@10 + (byte*) print_char_cursor#38 ← phi( main::@10/(byte*) print_char_cursor#18 ) + (byte*) print_line_cursor#15 ← phi( main::@10/(byte*) print_line_cursor#6 ) + (byte*) print_line_cursor#7 ← (byte*) print_line_cursor#15 + (byte*) print_char_cursor#19 ← (byte*) print_char_cursor#38 + return + to:@return +sub: scope:[sub] from main::@1 main::@5 main::@6 + (byte) sub::s#3 ← phi( main::@1/(byte) sub::s#0 main::@5/(byte) sub::s#1 main::@6/(byte) sub::s#2 ) + (byte) sub::idx#3 ← phi( main::@1/(byte) sub::idx#0 main::@5/(byte) sub::idx#1 main::@6/(byte) sub::idx#2 ) + *((signed word[]) words#0 + (byte) sub::idx#3) ← *((signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 + to:sub::@return +sub::@return: scope:[sub] from sub + return + to:@return +@21: scope:[] from @19 + (byte*) print_screen#10 ← phi( @19/(byte*) print_screen#11 ) + (byte*) print_char_cursor#47 ← phi( @19/(byte*) print_char_cursor#50 ) + (byte*) print_line_cursor#20 ← phi( @19/(byte*) print_line_cursor#23 ) + call main + to:@22 +@22: scope:[] from @21 + (byte*) print_char_cursor#39 ← phi( @21/(byte*) print_char_cursor#19 ) + (byte*) print_line_cursor#16 ← phi( @21/(byte*) print_line_cursor#7 ) + (byte*) print_line_cursor#8 ← (byte*) print_line_cursor#16 + (byte*) print_char_cursor#20 ← (byte*) print_char_cursor#39 + to:@end +@end: scope:[] from @22 + +SYMBOL TABLE SSA +(signed word/signed dword~) $0 +(signed word/signed dword~) $1 +(signed byte/signed word/signed dword~) $2 +(signed byte/signed word/signed dword~) $3 +(const string) $4 = (string) "0123456789abcdef" +(label) @12 +(label) @19 +(label) @21 +(label) @22 +(label) @begin +(label) @end +(void()) main() +(byte~) main::$0 +(bool~) main::$4 +(byte~) main::$6 +(bool~) main::$9 +(label) main::@1 +(label) main::@10 +(label) main::@2 +(label) main::@3 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@8 +(label) main::@9 +(label) main::@return +(byte) main::i +(byte) main::i#0 +(byte) main::i#1 +(byte) main::i#2 +(byte) main::i#3 +(byte) main::i#4 +(byte) main::i#5 +(byte) main::idx +(byte) main::idx#0 +(byte) main::idx#1 +(byte) main::idx#2 +(byte) main::j +(byte) main::j#0 +(byte) main::j#1 +(byte) main::j#2 +(byte) main::j#3 +(byte) main::j#4 +(void()) print_byte((byte) print_byte::b) +(byte~) print_byte::$0 +(byte~) print_byte::$2 +(label) print_byte::@1 +(label) print_byte::@2 +(label) print_byte::@return +(byte) print_byte::b +(byte) print_byte::b#0 +(byte) print_byte::b#1 +(byte) print_byte::b#2 +(byte) print_byte::b#3 +(void()) print_char((byte) print_char::ch) +(label) print_char::@return +(byte) print_char::ch +(byte) print_char::ch#0 +(byte) print_char::ch#1 +(byte) print_char::ch#2 +(byte) print_char::ch#3 +(byte*) print_char_cursor +(byte*) print_char_cursor#0 +(byte*) print_char_cursor#1 +(byte*) print_char_cursor#10 +(byte*) print_char_cursor#11 +(byte*) print_char_cursor#12 +(byte*) print_char_cursor#13 +(byte*) print_char_cursor#14 +(byte*) print_char_cursor#15 +(byte*) print_char_cursor#16 +(byte*) print_char_cursor#17 +(byte*) print_char_cursor#18 +(byte*) print_char_cursor#19 +(byte*) print_char_cursor#2 +(byte*) print_char_cursor#20 +(byte*) print_char_cursor#21 +(byte*) print_char_cursor#22 +(byte*) print_char_cursor#23 +(byte*) print_char_cursor#24 +(byte*) print_char_cursor#25 +(byte*) print_char_cursor#26 +(byte*) print_char_cursor#27 +(byte*) print_char_cursor#28 +(byte*) print_char_cursor#29 +(byte*) print_char_cursor#3 +(byte*) print_char_cursor#30 +(byte*) print_char_cursor#31 +(byte*) print_char_cursor#32 +(byte*) print_char_cursor#33 +(byte*) print_char_cursor#34 +(byte*) print_char_cursor#35 +(byte*) print_char_cursor#36 +(byte*) print_char_cursor#37 +(byte*) print_char_cursor#38 +(byte*) print_char_cursor#39 +(byte*) print_char_cursor#4 +(byte*) print_char_cursor#40 +(byte*) print_char_cursor#41 +(byte*) print_char_cursor#42 +(byte*) print_char_cursor#43 +(byte*) print_char_cursor#44 +(byte*) print_char_cursor#45 +(byte*) print_char_cursor#46 +(byte*) print_char_cursor#47 +(byte*) print_char_cursor#48 +(byte*) print_char_cursor#49 +(byte*) print_char_cursor#5 +(byte*) print_char_cursor#50 +(byte*) print_char_cursor#51 +(byte*) print_char_cursor#52 +(byte*) print_char_cursor#53 +(byte*) print_char_cursor#54 +(byte*) print_char_cursor#55 +(byte*) print_char_cursor#6 +(byte*) print_char_cursor#7 +(byte*) print_char_cursor#8 +(byte*) print_char_cursor#9 +(void()) print_cls() +(byte*~) print_cls::$0 +(bool~) print_cls::$1 +(label) print_cls::@1 +(label) print_cls::@2 +(label) print_cls::@return +(byte*) print_cls::sc +(byte*) print_cls::sc#0 +(byte*) print_cls::sc#1 +(byte*) print_cls::sc#2 +(byte[]) print_hextab +(byte[]) print_hextab#0 +(byte*) print_line_cursor +(byte*) print_line_cursor#0 +(byte*) print_line_cursor#1 +(byte*) print_line_cursor#10 +(byte*) print_line_cursor#11 +(byte*) print_line_cursor#12 +(byte*) print_line_cursor#13 +(byte*) print_line_cursor#14 +(byte*) print_line_cursor#15 +(byte*) print_line_cursor#16 +(byte*) print_line_cursor#17 +(byte*) print_line_cursor#18 +(byte*) print_line_cursor#19 +(byte*) print_line_cursor#2 +(byte*) print_line_cursor#20 +(byte*) print_line_cursor#21 +(byte*) print_line_cursor#22 +(byte*) print_line_cursor#23 +(byte*) print_line_cursor#24 +(byte*) print_line_cursor#25 +(byte*) print_line_cursor#26 +(byte*) print_line_cursor#27 +(byte*) print_line_cursor#28 +(byte*) print_line_cursor#3 +(byte*) print_line_cursor#4 +(byte*) print_line_cursor#5 +(byte*) print_line_cursor#6 +(byte*) print_line_cursor#7 +(byte*) print_line_cursor#8 +(byte*) print_line_cursor#9 +(void()) print_ln() +(byte*~) print_ln::$0 +(bool~) print_ln::$1 +(label) print_ln::@1 +(label) print_ln::@2 +(label) print_ln::@return +(byte*) print_screen +(byte*) print_screen#0 +(byte*) print_screen#1 +(byte*) print_screen#10 +(byte*) print_screen#11 +(byte*) print_screen#12 +(byte*) print_screen#2 +(byte*) print_screen#3 +(byte*) print_screen#4 +(byte*) print_screen#5 +(byte*) print_screen#6 +(byte*) print_screen#7 +(byte*) print_screen#8 +(byte*) print_screen#9 +(void()) print_sword((signed word) print_sword::w) +(bool~) print_sword::$0 +(bool~) print_sword::$1 +(signed word~) print_sword::$3 +(word~) print_sword::$4 +(label) print_sword::@1 +(label) print_sword::@2 +(label) print_sword::@3 +(label) print_sword::@4 +(label) print_sword::@return +(signed word) print_sword::w +(signed word) print_sword::w#0 +(signed word) print_sword::w#1 +(signed word) print_sword::w#2 +(signed word) print_sword::w#3 +(signed word) print_sword::w#4 +(signed word) print_sword::w#5 +(void()) print_word((word) print_word::w) +(byte~) print_word::$0 +(byte~) print_word::$2 +(label) print_word::@1 +(label) print_word::@2 +(label) print_word::@return +(word) print_word::w +(word) print_word::w#0 +(word) print_word::w#1 +(word) print_word::w#2 +(void()) sub((byte) sub::idx , (byte) sub::s) +(label) sub::@return +(byte) sub::idx +(byte) sub::idx#0 +(byte) sub::idx#1 +(byte) sub::idx#2 +(byte) sub::idx#3 +(byte) sub::s +(byte) sub::s#0 +(byte) sub::s#1 +(byte) sub::s#2 +(byte) sub::s#3 +(signed word[]) words +(signed word[]) words#0 + +Inversing boolean not [17] (bool~) print_sword::$1 ← (signed word) print_sword::w#2 >= (byte/signed byte/word/signed word/dword/signed dword) 0 from [16] (bool~) print_sword::$0 ← (signed word) print_sword::w#2 < (byte/signed byte/word/signed word/dword/signed dword) 0 +Successful SSA optimization Pass2UnaryNotSimplification +Alias (byte*) print_line_cursor#0 = (byte*) print_screen#0 (byte*) print_char_cursor#0 (byte*) print_line_cursor#24 (byte*) print_char_cursor#51 (byte*) print_screen#12 (byte*) print_line_cursor#23 (byte*) print_char_cursor#50 (byte*) print_screen#11 (byte*) print_line_cursor#20 (byte*) print_char_cursor#47 (byte*) print_screen#10 +Alias (byte*) print_line_cursor#1 = (byte*~) print_ln::$0 (byte*) print_line_cursor#10 (byte*) print_char_cursor#1 (byte*) print_line_cursor#11 (byte*) print_char_cursor#22 (byte*) print_line_cursor#2 (byte*) print_char_cursor#2 +Alias (word) print_word::w#0 = (word~) print_sword::$4 +Alias (byte*) print_char_cursor#23 = (byte*) print_char_cursor#3 (byte*) print_char_cursor#25 (byte*) print_char_cursor#5 +Alias (byte*) print_char_cursor#42 = (byte*) print_char_cursor#48 +Alias (signed word) print_sword::w#2 = (signed word) print_sword::w#5 (signed word) print_sword::w#4 +Alias (byte*) print_char_cursor#24 = (byte*) print_char_cursor#4 +Alias (signed word) print_sword::w#0 = (signed word~) print_sword::$3 +Alias (byte) print_byte::b#0 = (byte~) print_word::$0 +Alias (word) print_word::w#1 = (word) print_word::w#2 +Alias (byte*) print_char_cursor#26 = (byte*) print_char_cursor#6 +Alias (byte) print_byte::b#1 = (byte~) print_word::$2 +Alias (byte*) print_char_cursor#27 = (byte*) print_char_cursor#7 (byte*) print_char_cursor#28 (byte*) print_char_cursor#8 +Alias (byte) print_byte::b#2 = (byte) print_byte::b#3 +Alias (byte*) print_char_cursor#29 = (byte*) print_char_cursor#9 +Alias (byte*) print_char_cursor#10 = (byte*) print_char_cursor#30 (byte*) print_char_cursor#31 (byte*) print_char_cursor#11 +Alias (byte*) print_char_cursor#12 = (byte*) print_char_cursor#33 (byte*) print_char_cursor#13 +Alias (byte*) print_line_cursor#12 = (byte*) print_screen#3 (byte*) print_screen#2 (byte*) print_line_cursor#3 (byte*) print_char_cursor#14 (byte*) print_char_cursor#34 (byte*) print_line_cursor#4 (byte*) print_char_cursor#15 +Alias (byte) main::idx#0 = (byte~) main::$0 (byte) main::idx#1 (byte) main::idx#2 +Alias (byte) main::i#2 = (byte) main::i#5 (byte) main::i#4 (byte) main::i#3 +Alias (byte*) print_screen#4 = (byte*) print_screen#7 (byte*) print_screen#8 (byte*) print_screen#6 (byte*) print_screen#5 +Alias (byte*) print_line_cursor#18 = (byte*) print_line_cursor#26 (byte*) print_line_cursor#27 (byte*) print_line_cursor#25 (byte*) print_line_cursor#21 +Alias (byte*) print_char_cursor#45 = (byte*) print_char_cursor#53 (byte*) print_char_cursor#54 (byte*) print_char_cursor#52 (byte*) print_char_cursor#49 +Alias (byte*) print_line_cursor#13 = (byte*) print_line_cursor#5 +Alias (byte*) print_char_cursor#16 = (byte*) print_char_cursor#35 +Alias (byte*) print_line_cursor#19 = (byte*) print_line_cursor#22 +Alias (byte) main::j#2 = (byte) main::j#4 (byte) main::j#3 +Alias (byte*) print_char_cursor#17 = (byte*) print_char_cursor#36 +Alias (byte*) print_line_cursor#14 = (byte*) print_line_cursor#6 (byte*) print_line_cursor#15 (byte*) print_line_cursor#7 +Alias (byte*) print_char_cursor#18 = (byte*) print_char_cursor#37 (byte*) print_char_cursor#38 (byte*) print_char_cursor#19 +Alias (byte*) print_line_cursor#16 = (byte*) print_line_cursor#8 +Alias (byte*) print_char_cursor#20 = (byte*) print_char_cursor#39 +Successful SSA optimization Pass2AliasElimination +Self Phi Eliminated (byte*) print_char_cursor#21 +Self Phi Eliminated (byte*) print_line_cursor#12 +Self Phi Eliminated (byte*) print_screen#4 +Self Phi Eliminated (byte*) print_line_cursor#18 +Self Phi Eliminated (byte*) print_char_cursor#45 +Successful SSA optimization Pass2SelfPhiElimination +Redundant Phi (byte*) print_line_cursor#17 (byte*) print_line_cursor#19 +Redundant Phi (byte*) print_char_cursor#40 (byte*) print_char_cursor#17 +Redundant Phi (byte*) print_char_cursor#21 (byte*) print_char_cursor#40 +Redundant Phi (signed word) print_sword::w#2 (signed word) print_sword::w#1 +Redundant Phi (byte*) print_char_cursor#42 (byte*) print_char_cursor#46 +Redundant Phi (byte*) print_char_cursor#23 (byte*) print_char_cursor#27 +Redundant Phi (byte*) print_char_cursor#24 (byte*) print_char_cursor#12 +Redundant Phi (word) print_word::w#1 (word) print_word::w#0 +Redundant Phi (byte*) print_char_cursor#43 (byte*) print_char_cursor#41 +Redundant Phi (byte*) print_char_cursor#26 (byte*) print_char_cursor#10 +Redundant Phi (byte*) print_char_cursor#27 (byte*) print_char_cursor#10 +Redundant Phi (byte*) print_char_cursor#29 (byte*) print_char_cursor#12 +Redundant Phi (byte*) print_char_cursor#10 (byte*) print_char_cursor#12 +Redundant Phi (byte*) print_screen#1 (byte*) print_screen#4 +Redundant Phi (byte*) print_line_cursor#12 (byte*) print_screen#1 +Redundant Phi (byte*) print_screen#9 (byte*) print_line_cursor#0 +Redundant Phi (byte*) print_line_cursor#28 (byte*) print_line_cursor#0 +Redundant Phi (byte*) print_char_cursor#55 (byte*) print_line_cursor#0 +Redundant Phi (byte*) print_screen#4 (byte*) print_screen#9 +Redundant Phi (byte*) print_line_cursor#18 (byte*) print_line_cursor#28 +Redundant Phi (byte*) print_char_cursor#45 (byte*) print_char_cursor#55 +Redundant Phi (byte*) print_line_cursor#13 (byte*) print_line_cursor#12 +Redundant Phi (byte*) print_char_cursor#16 (byte*) print_line_cursor#12 +Redundant Phi (byte*) print_char_cursor#17 (byte*) print_char_cursor#23 +Redundant Phi (byte*) print_line_cursor#14 (byte*) print_line_cursor#1 +Redundant Phi (byte*) print_char_cursor#18 (byte*) print_line_cursor#1 +Redundant Phi (byte*) print_line_cursor#16 (byte*) print_line_cursor#14 +Redundant Phi (byte*) print_char_cursor#20 (byte*) print_char_cursor#18 +Successful SSA optimization Pass2RedundantPhiElimination +Simple Condition (bool~) print_ln::$1 [8] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 +Simple Condition (bool~) print_sword::$1 [18] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 +Simple Condition (bool~) print_cls::$1 [78] if((byte*) print_cls::sc#1!=(byte*~) print_cls::$0) goto print_cls::@1 +Simple Condition (bool~) main::$4 [111] if((byte) main::i#1!=rangelast(0,8)) goto main::@1 +Simple Condition (bool~) main::$9 [130] if((byte) main::j#1!=rangelast(0,8)) goto main::@2 +Successful SSA optimization Pass2ConditionalJumpSimplification +Constant (const byte*) print_line_cursor#0 = ((byte*))$400 +Constant (const byte) print_char::ch#0 = '-' +Constant (const byte[]) print_hextab#0 = $4 +Constant (const signed word/signed dword) $0 = -$6000 +Constant (const signed word/signed dword) $1 = -$600 +Constant (const signed byte/signed word/signed dword) $2 = -$60 +Constant (const signed byte/signed word/signed dword) $3 = -6 +Constant (const byte) main::i#0 = 0 +Constant (const byte) sub::s#0 = $80 +Constant (const byte) sub::s#1 = $40 +Constant (const byte) sub::s#2 = $40 +Constant (const byte) main::j#0 = 0 +Successful SSA optimization Pass2ConstantIdentification +Constant (const byte*) print_cls::sc#0 = print_line_cursor#0 +Constant (const byte*) print_cls::$0 = print_line_cursor#0+$3e8 +Constant (const signed word[]) words#0 = { $0, $1, $2, $3, 0, 6, $60, $600, $6000 } +Successful SSA optimization Pass2ConstantIdentification +Eliminating Noop Cast (word) print_word::w#0 ← ((word)) (signed word) print_sword::w#3 +Successful SSA optimization Pass2NopCastElimination +Resolved ranged next value main::i#1 ← ++ main::i#2 to ++ +Resolved ranged comparison value if(main::i#1!=rangelast(0,8)) goto main::@1 to (byte/signed byte/word/signed word/dword/signed dword) 9 +Resolved ranged next value main::j#1 ← ++ main::j#2 to ++ +Resolved ranged comparison value if(main::j#1!=rangelast(0,8)) goto main::@2 to (byte/signed byte/word/signed word/dword/signed dword) 9 +Culled Empty Block (label) print_ln::@2 +Culled Empty Block (label) print_sword::@3 +Culled Empty Block (label) print_word::@2 +Culled Empty Block (label) @12 +Culled Empty Block (label) print_byte::@2 +Culled Empty Block (label) print_cls::@2 +Culled Empty Block (label) @19 +Culled Empty Block (label) main::@8 +Culled Empty Block (label) @22 +Successful SSA optimization Pass2CullEmptyBlocks +Inlining constant with var siblings (const byte) print_char::ch#0 +Inlining constant with var siblings (const byte*) print_cls::sc#0 +Inlining constant with var siblings (const byte) main::i#0 +Inlining constant with var siblings (const byte) main::j#0 +Inlining constant with var siblings (const byte) sub::s#0 +Inlining constant with var siblings (const byte) sub::s#1 +Inlining constant with var siblings (const byte) sub::s#2 +Inlining constant with var siblings (const byte*) print_line_cursor#0 +Constant inlined print_cls::$0 = ((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8 +Constant inlined print_line_cursor#0 = ((byte*))(word/signed word/dword/signed dword) $400 +Constant inlined sub::s#0 = (byte/word/signed word/dword/signed dword) $80 +Constant inlined sub::s#1 = (byte/signed byte/word/signed word/dword/signed dword) $40 +Constant inlined sub::s#2 = (byte/signed byte/word/signed word/dword/signed dword) $40 +Constant inlined $0 = -(word/signed word/dword/signed dword) $6000 +Constant inlined print_cls::sc#0 = ((byte*))(word/signed word/dword/signed dword) $400 +Constant inlined $1 = -(word/signed word/dword/signed dword) $600 +Constant inlined $2 = -(byte/signed byte/word/signed word/dword/signed dword) $60 +Constant inlined $3 = -(byte/signed byte/word/signed word/dword/signed dword) 6 +Constant inlined $4 = (const byte[]) print_hextab#0 +Constant inlined print_char::ch#0 = (byte) '-' +Constant inlined main::i#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 +Constant inlined main::j#0 = (byte/signed byte/word/signed word/dword/signed dword) 0 +Successful SSA optimization Pass2ConstantInlining +Added new block during phi lifting main::@11(between main::@7 and main::@1) +Added new block during phi lifting main::@12(between main::@10 and main::@2) +Added new block during phi lifting print_ln::@3(between print_ln::@1 and print_ln::@1) +Added new block during phi lifting print_sword::@5(between print_sword and print_sword::@1) +Added new block during phi lifting print_cls::@3(between print_cls::@1 and print_cls::@1) +Adding NOP phi() at start of @begin +Adding NOP phi() at start of @21 +Adding NOP phi() at start of @end +Adding NOP phi() at start of main +Adding NOP phi() at start of main::@3 +Adding NOP phi() at start of main::@9 +Adding NOP phi() at start of print_cls +CALL GRAPH +Calls in [] to main:2 +Calls in [main] to sub:9 sub:12 sub:15 print_cls:19 print_sword:23 print_ln:25 +Calls in [print_sword] to print_char:41 print_word:46 +Calls in [print_word] to print_byte:53 print_byte:57 +Calls in [print_byte] to print_char:64 print_char:69 + +Created 14 initial phi equivalence classes +Coalesced [8] sub::idx#4 ← sub::idx#0 +Coalesced [11] sub::idx#5 ← sub::idx#1 +Coalesced [14] sub::idx#6 ← sub::idx#2 +Coalesced [29] main::j#5 ← main::j#1 +Not coalescing [30] print_char_cursor#56 ← print_line_cursor#1 +Coalesced [31] print_line_cursor#29 ← print_line_cursor#1 +Coalesced [32] main::i#6 ← main::i#1 +Coalesced [33] print_line_cursor#30 ← print_line_cursor#19 +Coalesced (already) [38] print_line_cursor#31 ← print_line_cursor#1 +Coalesced [40] print_char_cursor#63 ← print_char_cursor#46 +Coalesced [43] print_sword::w#7 ← print_sword::w#0 +Coalesced [44] print_char_cursor#58 ← print_char_cursor#12 +Coalesced [48] print_sword::w#6 ← print_sword::w#1 +Coalesced [49] print_char_cursor#57 ← print_char_cursor#46 +Coalesced [51] print_byte::b#4 ← print_byte::b#0 +Coalesced [52] print_char_cursor#59 ← print_char_cursor#41 +Coalesced [55] print_byte::b#5 ← print_byte::b#1 +Coalesced (already) [56] print_char_cursor#60 ← print_char_cursor#12 +Coalesced [62] print_char::ch#4 ← print_char::ch#1 +Coalesced (already) [63] print_char_cursor#61 ← print_char_cursor#44 +Coalesced [67] print_char::ch#5 ← print_char::ch#2 +Coalesced (already) [68] print_char_cursor#62 ← print_char_cursor#12 +Coalesced [81] print_cls::sc#3 ← print_cls::sc#1 +Coalesced down to 10 phi equivalence classes +Culled Empty Block (label) main::@11 +Culled Empty Block (label) print_ln::@3 +Culled Empty Block (label) print_sword::@5 +Culled Empty Block (label) print_cls::@3 +Adding NOP phi() at start of @begin +Adding NOP phi() at start of @21 +Adding NOP phi() at start of @end +Adding NOP phi() at start of main +Adding NOP phi() at start of main::@3 +Adding NOP phi() at start of main::@9 +Adding NOP phi() at start of print_ln +Adding NOP phi() at start of print_sword::@2 +Adding NOP phi() at start of print_cls + +FINAL CONTROL FLOW GRAPH +@begin: scope:[] from + [0] phi() + to:@21 +@21: scope:[] from @begin + [1] phi() + [2] call main + to:@end +@end: scope:[] from @21 + [3] phi() +main: scope:[main] from @21 + [4] phi() + to:main::@1 +main::@1: scope:[main] from main main::@7 + [5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 ) + [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [7] (byte) sub::idx#0 ← (byte) main::idx#0 + [8] call sub + to:main::@5 +main::@5: scope:[main] from main::@1 + [9] (byte) sub::idx#1 ← (byte) main::idx#0 + [10] call sub + to:main::@6 +main::@6: scope:[main] from main::@5 + [11] (byte) sub::idx#2 ← (byte) main::idx#0 + [12] call sub + to:main::@7 +main::@7: scope:[main] from main::@6 + [13] (byte) main::i#1 ← ++ (byte) main::i#2 + [14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 + to:main::@3 +main::@3: scope:[main] from main::@7 + [15] phi() + [16] call print_cls + to:main::@2 +main::@2: scope:[main] from main::@12 main::@3 + [17] (byte*) print_line_cursor#19 ← phi( main::@12/(byte*) print_line_cursor#1 main::@3/((byte*))(word/signed word/dword/signed dword) $400 ) + [17] (byte*) print_char_cursor#46 ← phi( main::@12/(byte*~) print_char_cursor#56 main::@3/((byte*))(word/signed word/dword/signed dword) $400 ) + [17] (byte) main::j#2 ← phi( main::@12/(byte) main::j#1 main::@3/(byte/signed byte/word/signed word/dword/signed dword) 0 ) + [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 + [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) + [20] call print_sword + to:main::@9 +main::@9: scope:[main] from main::@2 + [21] phi() + [22] call print_ln + to:main::@10 +main::@10: scope:[main] from main::@9 + [23] (byte) main::j#1 ← ++ (byte) main::j#2 + [24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12 + to:main::@return +main::@return: scope:[main] from main::@10 + [25] return + to:@return +main::@12: scope:[main] from main::@10 + [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 + to:main::@2 +print_ln: scope:[print_ln] from main::@9 + [27] phi() + to:print_ln::@1 +print_ln::@1: scope:[print_ln] from print_ln print_ln::@1 + [28] (byte*) print_line_cursor#9 ← phi( print_ln/(byte*) print_line_cursor#19 print_ln::@1/(byte*) print_line_cursor#1 ) + [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 + [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 + to:print_ln::@return +print_ln::@return: scope:[print_ln] from print_ln::@1 + [31] return + to:@return +print_sword: scope:[print_sword] from main::@2 + [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 + to:print_sword::@2 +print_sword::@2: scope:[print_sword] from print_sword + [33] phi() + [34] call print_char + to:print_sword::@4 +print_sword::@4: scope:[print_sword] from print_sword::@2 + [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 + to:print_sword::@1 +print_sword::@1: scope:[print_sword] from print_sword print_sword::@4 + [36] (byte*) print_char_cursor#41 ← phi( print_sword/(byte*) print_char_cursor#46 print_sword::@4/(byte*) print_char_cursor#12 ) + [36] (signed word) print_sword::w#3 ← phi( print_sword/(signed word) print_sword::w#1 print_sword::@4/(signed word) print_sword::w#0 ) + [37] call print_word + to:print_sword::@return +print_sword::@return: scope:[print_sword] from print_sword::@1 + [38] return + to:@return +print_word: scope:[print_word] from print_sword::@1 + [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 + [40] call print_byte + to:print_word::@1 +print_word::@1: scope:[print_word] from print_word + [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 + [42] call print_byte + to:print_word::@return +print_word::@return: scope:[print_word] from print_word::@1 + [43] return + to:@return +print_byte: scope:[print_byte] from print_word print_word::@1 + [44] (byte*) print_char_cursor#44 ← phi( print_word/(byte*) print_char_cursor#41 print_word::@1/(byte*) print_char_cursor#12 ) + [44] (byte) print_byte::b#2 ← phi( print_word/(byte) print_byte::b#0 print_word::@1/(byte) print_byte::b#1 ) + [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 + [46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) + [47] call print_char + to:print_byte::@1 +print_byte::@1: scope:[print_byte] from print_byte + [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f + [49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) + [50] call print_char + to:print_byte::@return +print_byte::@return: scope:[print_byte] from print_byte::@1 + [51] return + to:@return +print_char: scope:[print_char] from print_byte print_byte::@1 print_sword::@2 + [52] (byte*) print_char_cursor#32 ← phi( print_byte/(byte*) print_char_cursor#44 print_byte::@1/(byte*) print_char_cursor#12 print_sword::@2/(byte*) print_char_cursor#46 ) + [52] (byte) print_char::ch#3 ← phi( print_byte/(byte) print_char::ch#1 print_byte::@1/(byte) print_char::ch#2 print_sword::@2/(byte) '-' ) + [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 + [54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 + to:print_char::@return +print_char::@return: scope:[print_char] from print_char + [55] return + to:@return +print_cls: scope:[print_cls] from main::@3 + [56] phi() + to:print_cls::@1 +print_cls::@1: scope:[print_cls] from print_cls print_cls::@1 + [57] (byte*) print_cls::sc#2 ← phi( print_cls/((byte*))(word/signed word/dword/signed dword) $400 print_cls::@1/(byte*) print_cls::sc#1 ) + [58] *((byte*) print_cls::sc#2) ← (byte) ' ' + [59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 + [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 + to:print_cls::@return +print_cls::@return: scope:[print_cls] from print_cls::@1 + [61] return + to:@return +sub: scope:[sub] from main::@1 main::@5 main::@6 + [62] (byte) sub::s#3 ← phi( main::@1/(byte/word/signed word/dword/signed dword) $80 main::@5/(byte/signed byte/word/signed word/dword/signed dword) $40 main::@6/(byte/signed byte/word/signed word/dword/signed dword) $40 ) + [62] (byte) sub::idx#3 ← phi( main::@1/(byte) sub::idx#0 main::@5/(byte) sub::idx#1 main::@6/(byte) sub::idx#2 ) + [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 + to:sub::@return +sub::@return: scope:[sub] from sub + [64] return + to:@return + + +VARIABLE REGISTER WEIGHTS +(void()) main() +(byte~) main::$6 22.0 +(byte) main::i +(byte) main::i#1 16.5 +(byte) main::i#2 4.125 +(byte) main::idx +(byte) main::idx#0 8.8 +(byte) main::j +(byte) main::j#1 11.0 +(byte) main::j#2 5.5 +(void()) print_byte((byte) print_byte::b) +(byte~) print_byte::$0 4.0 +(byte~) print_byte::$2 4.0 +(byte) print_byte::b +(byte) print_byte::b#0 4.0 +(byte) print_byte::b#1 4.0 +(byte) print_byte::b#2 2.0 +(void()) print_char((byte) print_char::ch) +(byte) print_char::ch +(byte) print_char::ch#1 4.0 +(byte) print_char::ch#2 4.0 +(byte) print_char::ch#3 6.0 +(byte*) print_char_cursor +(byte*) print_char_cursor#12 5.190476190476189 +(byte*) print_char_cursor#32 5.0 +(byte*) print_char_cursor#41 3.0 +(byte*) print_char_cursor#44 2.0 +(byte*) print_char_cursor#46 3.0 +(byte*~) print_char_cursor#56 22.0 +(void()) print_cls() +(byte*) print_cls::sc +(byte*) print_cls::sc#1 16.5 +(byte*) print_cls::sc#2 16.5 +(byte[]) print_hextab +(byte*) print_line_cursor +(byte*) print_line_cursor#1 46.42857142857143 +(byte*) print_line_cursor#19 2.1666666666666665 +(byte*) print_line_cursor#9 204.0 +(void()) print_ln() +(byte*) print_screen +(void()) print_sword((signed word) print_sword::w) +(signed word) print_sword::w +(signed word) print_sword::w#0 4.0 +(signed word) print_sword::w#1 4.25 +(signed word) print_sword::w#3 1.3333333333333333 +(void()) print_word((word) print_word::w) +(word) print_word::w +(void()) sub((byte) sub::idx , (byte) sub::s) +(byte) sub::idx +(byte) sub::idx#0 22.0 +(byte) sub::idx#1 22.0 +(byte) sub::idx#2 22.0 +(byte) sub::idx#3 37.0 +(byte) sub::s +(byte) sub::s#3 2.0 +(signed word[]) words + +Initial phi equivalence classes +[ main::i#2 main::i#1 ] +[ main::j#2 main::j#1 ] +[ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] +[ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +[ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +[ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +[ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +[ print_cls::sc#2 print_cls::sc#1 ] +[ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] +[ sub::s#3 ] +Added variable main::idx#0 to zero page equivalence class [ main::idx#0 ] +Added variable main::$6 to zero page equivalence class [ main::$6 ] +Added variable print_byte::$0 to zero page equivalence class [ print_byte::$0 ] +Added variable print_byte::$2 to zero page equivalence class [ print_byte::$2 ] +Complete equivalence classes +[ main::i#2 main::i#1 ] +[ main::j#2 main::j#1 ] +[ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] +[ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +[ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +[ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +[ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +[ print_cls::sc#2 print_cls::sc#1 ] +[ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] +[ sub::s#3 ] +[ main::idx#0 ] +[ main::$6 ] +[ print_byte::$0 ] +[ print_byte::$2 ] +Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Allocated zp ZP_BYTE:3 [ main::j#2 main::j#1 ] +Allocated zp ZP_WORD:4 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] +Allocated zp ZP_WORD:6 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +Allocated zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Allocated zp ZP_BYTE:9 [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +Allocated zp ZP_WORD:10 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +Allocated zp ZP_WORD:12 [ print_cls::sc#2 print_cls::sc#1 ] +Allocated zp ZP_BYTE:14 [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] +Allocated zp ZP_BYTE:15 [ sub::s#3 ] +Allocated zp ZP_BYTE:16 [ main::idx#0 ] +Allocated zp ZP_BYTE:17 [ main::$6 ] +Allocated zp ZP_BYTE:18 [ print_byte::$0 ] +Allocated zp ZP_BYTE:19 [ print_byte::$2 ] + +INITIAL ASM +//SEG0 File Comments +// Tests that signed indexed subtract works as intended +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(bbegin) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label print_line_cursor = 4 + .label print_char_cursor = $a +//SEG3 @begin +bbegin: +//SEG4 [1] phi from @begin to @21 [phi:@begin->@21] +b21_from_bbegin: + jmp b21 +//SEG5 @21 +b21: +//SEG6 [2] call main +//SEG7 [4] phi from @21 to main [phi:@21->main] +main_from_b21: + jsr main +//SEG8 [3] phi from @21 to @end [phi:@21->@end] +bend_from_b21: + jmp bend +//SEG9 @end +bend: +//SEG10 main +main: { + .label _6 = $11 + .label idx = $10 + .label i = 2 + .label j = 3 + //SEG11 [5] phi from main to main::@1 [phi:main->main::@1] + b1_from_main: + //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 + lda #0 + sta i + jmp b1 + //SEG13 [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1] + b1_from_b7: + //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#0] -- register_copy + jmp b1 + //SEG15 main::@1 + b1: + //SEG16 [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + lda i + asl + sta idx + //SEG17 [7] (byte) sub::idx#0 ← (byte) main::idx#0 -- vbuz1=vbuz2 + lda idx + sta sub.idx + //SEG18 [8] call sub + //SEG19 [62] phi from main::@1 to sub [phi:main::@1->sub] + sub_from_b1: + //SEG20 [62] phi (byte) sub::s#3 = (byte/word/signed word/dword/signed dword) $80 [phi:main::@1->sub#0] -- vbuz1=vbuc1 + lda #$80 + sta sub.s + //SEG21 [62] phi (byte) sub::idx#3 = (byte) sub::idx#0 [phi:main::@1->sub#1] -- register_copy + jsr sub + jmp b5 + //SEG22 main::@5 + b5: + //SEG23 [9] (byte) sub::idx#1 ← (byte) main::idx#0 -- vbuz1=vbuz2 + lda idx + sta sub.idx + //SEG24 [10] call sub + //SEG25 [62] phi from main::@5 to sub [phi:main::@5->sub] + sub_from_b5: + //SEG26 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@5->sub#0] -- vbuz1=vbuc1 + lda #$40 + sta sub.s + //SEG27 [62] phi (byte) sub::idx#3 = (byte) sub::idx#1 [phi:main::@5->sub#1] -- register_copy + jsr sub + jmp b6 + //SEG28 main::@6 + b6: + //SEG29 [11] (byte) sub::idx#2 ← (byte) main::idx#0 -- vbuz1=vbuz2 + lda idx + sta sub.idx + //SEG30 [12] call sub + //SEG31 [62] phi from main::@6 to sub [phi:main::@6->sub] + sub_from_b6: + //SEG32 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@6->sub#0] -- vbuz1=vbuc1 + lda #$40 + sta sub.s + //SEG33 [62] phi (byte) sub::idx#3 = (byte) sub::idx#2 [phi:main::@6->sub#1] -- register_copy + jsr sub + jmp b7 + //SEG34 main::@7 + b7: + //SEG35 [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 + inc i + //SEG36 [14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 + lda i + cmp #9 + bne b1_from_b7 + //SEG37 [15] phi from main::@7 to main::@3 [phi:main::@7->main::@3] + b3_from_b7: + jmp b3 + //SEG38 main::@3 + b3: + //SEG39 [16] call print_cls + //SEG40 [56] phi from main::@3 to print_cls [phi:main::@3->print_cls] + print_cls_from_b3: + jsr print_cls + //SEG41 [17] phi from main::@3 to main::@2 [phi:main::@3->main::@2] + b2_from_b3: + //SEG42 [17] phi (byte*) print_line_cursor#19 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 + lda #<$400 + sta print_line_cursor + lda #>$400 + sta print_line_cursor+1 + //SEG43 [17] phi (byte*) print_char_cursor#46 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#1] -- pbuz1=pbuc1 + lda #<$400 + sta print_char_cursor + lda #>$400 + sta print_char_cursor+1 + //SEG44 [17] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#2] -- vbuz1=vbuc1 + lda #0 + sta j + jmp b2 + //SEG45 main::@2 + b2: + //SEG46 [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuz1=vbuz2_rol_1 + lda j + asl + sta _6 + //SEG47 [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) -- vwsz1=pwsc1_derefidx_vbuz2 + ldy _6 + lda words,y + sta print_sword.w + lda words+1,y + sta print_sword.w+1 + //SEG48 [20] call print_sword + jsr print_sword + //SEG49 [21] phi from main::@2 to main::@9 [phi:main::@2->main::@9] + b9_from_b2: + jmp b9 + //SEG50 main::@9 + b9: + //SEG51 [22] call print_ln + //SEG52 [27] phi from main::@9 to print_ln [phi:main::@9->print_ln] + print_ln_from_b9: + jsr print_ln + jmp b10 + //SEG53 main::@10 + b10: + //SEG54 [23] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuz1=_inc_vbuz1 + inc j + //SEG55 [24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12 -- vbuz1_neq_vbuc1_then_la1 + lda j + cmp #9 + bne b12 + jmp breturn + //SEG56 main::@return + breturn: + //SEG57 [25] return + rts + //SEG58 main::@12 + b12: + //SEG59 [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 -- pbuz1=pbuz2 + lda print_line_cursor + sta print_char_cursor + lda print_line_cursor+1 + sta print_char_cursor+1 + //SEG60 [17] phi from main::@12 to main::@2 [phi:main::@12->main::@2] + b2_from_b12: + //SEG61 [17] phi (byte*) print_line_cursor#19 = (byte*) print_line_cursor#1 [phi:main::@12->main::@2#0] -- register_copy + //SEG62 [17] phi (byte*) print_char_cursor#46 = (byte*~) print_char_cursor#56 [phi:main::@12->main::@2#1] -- register_copy + //SEG63 [17] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@12->main::@2#2] -- register_copy + jmp b2 +} +//SEG64 print_ln +// Print a newline +print_ln: { + //SEG65 [28] phi from print_ln print_ln::@1 to print_ln::@1 [phi:print_ln/print_ln::@1->print_ln::@1] + b1_from_print_ln: + b1_from_b1: + //SEG66 [28] phi (byte*) print_line_cursor#9 = (byte*) print_line_cursor#19 [phi:print_ln/print_ln::@1->print_ln::@1#0] -- register_copy + jmp b1 + //SEG67 print_ln::@1 + b1: + //SEG68 [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 -- pbuz1=pbuz1_plus_vbuc1 + lda print_line_cursor + clc + adc #$28 + sta print_line_cursor + bcc !+ + inc print_line_cursor+1 + !: + //SEG69 [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 -- pbuz1_lt_pbuz2_then_la1 + lda print_line_cursor+1 + cmp print_char_cursor+1 + bcc b1_from_b1 + bne !+ + lda print_line_cursor + cmp print_char_cursor + bcc b1_from_b1 + !: + jmp breturn + //SEG70 print_ln::@return + breturn: + //SEG71 [31] return + rts +} +//SEG72 print_sword +// Print a signed word as HEX +// print_sword(signed word zeropage(6) w) +print_sword: { + .label w = 6 + //SEG73 [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 -- vwsz1_ge_0_then_la1 + lda w+1 + bpl b1_from_print_sword + //SEG74 [33] phi from print_sword to print_sword::@2 [phi:print_sword->print_sword::@2] + b2_from_print_sword: + jmp b2 + //SEG75 print_sword::@2 + b2: + //SEG76 [34] call print_char + //SEG77 [52] phi from print_sword::@2 to print_char [phi:print_sword::@2->print_char] + print_char_from_b2: + //SEG78 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#46 [phi:print_sword::@2->print_char#0] -- register_copy + //SEG79 [52] phi (byte) print_char::ch#3 = (byte) '-' [phi:print_sword::@2->print_char#1] -- vbuz1=vbuc1 + lda #'-' + sta print_char.ch + jsr print_char + jmp b4 + //SEG80 print_sword::@4 + b4: + //SEG81 [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 -- vwsz1=_neg_vwsz1 + sec + lda w + eor #$ff + adc #0 + sta w + lda w+1 + eor #$ff + adc #0 + sta w+1 + //SEG82 [36] phi from print_sword print_sword::@4 to print_sword::@1 [phi:print_sword/print_sword::@4->print_sword::@1] + b1_from_print_sword: + b1_from_b4: + //SEG83 [36] phi (byte*) print_char_cursor#41 = (byte*) print_char_cursor#46 [phi:print_sword/print_sword::@4->print_sword::@1#0] -- register_copy + //SEG84 [36] phi (signed word) print_sword::w#3 = (signed word) print_sword::w#1 [phi:print_sword/print_sword::@4->print_sword::@1#1] -- register_copy + jmp b1 + //SEG85 print_sword::@1 + b1: + //SEG86 [37] call print_word + jsr print_word + jmp breturn + //SEG87 print_sword::@return + breturn: + //SEG88 [38] return + rts +} +//SEG89 print_word +// Print a word as HEX +print_word: { + //SEG90 [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 -- vbuz1=_hi_vwuz2 + lda print_sword.w+1 + sta print_byte.b + //SEG91 [40] call print_byte + //SEG92 [44] phi from print_word to print_byte [phi:print_word->print_byte] + print_byte_from_print_word: + //SEG93 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#41 [phi:print_word->print_byte#0] -- register_copy + //SEG94 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#0 [phi:print_word->print_byte#1] -- register_copy + jsr print_byte + jmp b1 + //SEG95 print_word::@1 + b1: + //SEG96 [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 -- vbuz1=_lo_vwuz2 + lda print_sword.w + sta print_byte.b + //SEG97 [42] call print_byte + //SEG98 [44] phi from print_word::@1 to print_byte [phi:print_word::@1->print_byte] + print_byte_from_b1: + //SEG99 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#12 [phi:print_word::@1->print_byte#0] -- register_copy + //SEG100 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#1 [phi:print_word::@1->print_byte#1] -- register_copy + jsr print_byte + jmp breturn + //SEG101 print_word::@return + breturn: + //SEG102 [43] return + rts +} +//SEG103 print_byte +// Print a byte as HEX +// print_byte(byte zeropage(8) b) +print_byte: { + .label _0 = $12 + .label _2 = $13 + .label b = 8 + //SEG104 [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 -- vbuz1=vbuz2_ror_4 + lda b + lsr + lsr + lsr + lsr + sta _0 + //SEG105 [46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) -- vbuz1=pbuc1_derefidx_vbuz2 + ldy _0 + lda print_hextab,y + sta print_char.ch + //SEG106 [47] call print_char + //SEG107 [52] phi from print_byte to print_char [phi:print_byte->print_char] + print_char_from_print_byte: + //SEG108 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#44 [phi:print_byte->print_char#0] -- register_copy + //SEG109 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#1 [phi:print_byte->print_char#1] -- register_copy + jsr print_char + jmp b1 + //SEG110 print_byte::@1 + b1: + //SEG111 [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f -- vbuz1=vbuz2_band_vbuc1 + lda #$f + and b + sta _2 + //SEG112 [49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) -- vbuz1=pbuc1_derefidx_vbuz2 + ldy _2 + lda print_hextab,y + sta print_char.ch + //SEG113 [50] call print_char + //SEG114 [52] phi from print_byte::@1 to print_char [phi:print_byte::@1->print_char] + print_char_from_b1: + //SEG115 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#12 [phi:print_byte::@1->print_char#0] -- register_copy + //SEG116 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#2 [phi:print_byte::@1->print_char#1] -- register_copy + jsr print_char + jmp breturn + //SEG117 print_byte::@return + breturn: + //SEG118 [51] return + rts +} +//SEG119 print_char +// Print a single char +// print_char(byte zeropage(9) ch) +print_char: { + .label ch = 9 + //SEG120 [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 -- _deref_pbuz1=vbuz2 + lda ch + ldy #0 + sta (print_char_cursor),y + //SEG121 [54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 -- pbuz1=_inc_pbuz1 + inc print_char_cursor + bne !+ + inc print_char_cursor+1 + !: + jmp breturn + //SEG122 print_char::@return + breturn: + //SEG123 [55] return + rts +} +//SEG124 print_cls +// Clear the screen. Also resets current line/char cursor. +print_cls: { + .label sc = $c + //SEG125 [57] phi from print_cls to print_cls::@1 [phi:print_cls->print_cls::@1] + b1_from_print_cls: + //SEG126 [57] phi (byte*) print_cls::sc#2 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:print_cls->print_cls::@1#0] -- pbuz1=pbuc1 + lda #<$400 + sta sc + lda #>$400 + sta sc+1 + jmp b1 + //SEG127 [57] phi from print_cls::@1 to print_cls::@1 [phi:print_cls::@1->print_cls::@1] + b1_from_b1: + //SEG128 [57] phi (byte*) print_cls::sc#2 = (byte*) print_cls::sc#1 [phi:print_cls::@1->print_cls::@1#0] -- register_copy + jmp b1 + //SEG129 print_cls::@1 + b1: + //SEG130 [58] *((byte*) print_cls::sc#2) ← (byte) ' ' -- _deref_pbuz1=vbuc1 + lda #' ' + ldy #0 + sta (sc),y + //SEG131 [59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 -- pbuz1=_inc_pbuz1 + inc sc + bne !+ + inc sc+1 + !: + //SEG132 [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 -- pbuz1_neq_pbuc1_then_la1 + lda sc+1 + cmp #>$400+$3e8 + bne b1_from_b1 + lda sc + cmp #<$400+$3e8 + bne b1_from_b1 + jmp breturn + //SEG133 print_cls::@return + breturn: + //SEG134 [61] return + rts +} +//SEG135 sub +// sub(byte zeropage($e) idx, byte zeropage($f) s) +sub: { + .label idx = $e + .label s = $f + //SEG136 [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 -- pwsc1_derefidx_vbuz1=pwsc1_derefidx_vbuz1_minus_vbuz2 + ldx idx + sec + lda words,x + sbc s + sta words,x + bcs !+ + dec words+1,x + !: + jmp breturn + //SEG137 sub::@return + breturn: + //SEG138 [64] return + rts +} + print_hextab: .text "0123456789abcdef" + words: .word -$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000 + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::idx#0 ] ( main:2 [ main::i#2 main::idx#0 ] ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ] +Statement [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::j#2 print_char_cursor#46 print_line_cursor#19 main::$6 ] ( main:2 [ main::j#2 print_char_cursor#46 print_line_cursor#19 main::$6 ] ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ] +Statement [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) [ main::j#2 print_char_cursor#46 print_line_cursor#19 print_sword::w#1 ] ( main:2 [ main::j#2 print_char_cursor#46 print_line_cursor#19 print_sword::w#1 ] ) always clobbers reg byte a +Statement [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 [ main::j#1 print_char_cursor#56 print_line_cursor#1 ] ( main:2 [ main::j#1 print_char_cursor#56 print_line_cursor#1 ] ) always clobbers reg byte a +Statement [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 [ print_line_cursor#1 print_char_cursor#12 ] ( main:2::print_ln:22 [ main::j#2 print_line_cursor#1 print_char_cursor#12 ] ) always clobbers reg byte a +Statement [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 [ print_line_cursor#1 print_char_cursor#12 ] ( main:2::print_ln:22 [ main::j#2 print_line_cursor#1 print_char_cursor#12 ] ) always clobbers reg byte a +Statement [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 [ print_char_cursor#46 print_sword::w#1 ] ( main:2::print_sword:20 [ main::j#2 print_line_cursor#19 print_char_cursor#46 print_sword::w#1 ] ) always clobbers reg byte a +Statement [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 [ print_char_cursor#12 print_sword::w#0 ] ( main:2::print_sword:20 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_sword::w#0 ] ) always clobbers reg byte a +Statement [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 [ print_sword::w#3 print_char_cursor#41 print_byte::b#0 ] ( main:2::print_sword:20::print_word:37 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#41 print_byte::b#0 ] ) always clobbers reg byte a +Statement [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 [ print_char_cursor#12 print_byte::b#1 ] ( main:2::print_sword:20::print_word:37 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_byte::b#1 ] ) always clobbers reg byte a +Statement [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 [ print_byte::b#2 print_char_cursor#44 print_byte::$0 ] ( main:2::print_sword:20::print_word:37::print_byte:40 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_byte::b#2 print_char_cursor#44 print_byte::$0 ] main:2::print_sword:20::print_word:37::print_byte:42 [ main::j#2 print_line_cursor#19 print_byte::b#2 print_char_cursor#44 print_byte::$0 ] ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Statement [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f [ print_char_cursor#12 print_byte::$2 ] ( main:2::print_sword:20::print_word:37::print_byte:40 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#12 print_byte::$2 ] main:2::print_sword:20::print_word:37::print_byte:42 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_byte::$2 ] ) always clobbers reg byte a +Statement [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 [ print_char_cursor#32 ] ( main:2::print_sword:20::print_char:34 [ main::j#2 print_line_cursor#19 print_sword::w#1 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:40::print_char:47 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_byte::b#2 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:42::print_char:47 [ main::j#2 print_line_cursor#19 print_byte::b#2 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:40::print_char:50 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:42::print_char:50 [ main::j#2 print_line_cursor#19 print_char_cursor#32 ] ) always clobbers reg byte y +Removing always clobbered register reg byte y as potential for zp ZP_BYTE:3 [ main::j#2 main::j#1 ] +Removing always clobbered register reg byte y as potential for zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Statement [58] *((byte*) print_cls::sc#2) ← (byte) ' ' [ print_cls::sc#2 ] ( main:2::print_cls:16 [ print_cls::sc#2 ] ) always clobbers reg byte a reg byte y +Statement [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 [ print_cls::sc#1 ] ( main:2::print_cls:16 [ print_cls::sc#1 ] ) always clobbers reg byte a +Statement [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 [ ] ( main:2::sub:8 [ main::i#2 main::idx#0 ] main:2::sub:10 [ main::i#2 main::idx#0 ] main:2::sub:12 [ main::i#2 ] ) always clobbers reg byte a +Removing always clobbered register reg byte a as potential for zp ZP_BYTE:16 [ main::idx#0 ] +Statement [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::i#2 main::idx#0 ] ( main:2 [ main::i#2 main::idx#0 ] ) always clobbers reg byte a +Statement [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 [ main::j#2 print_char_cursor#46 print_line_cursor#19 main::$6 ] ( main:2 [ main::j#2 print_char_cursor#46 print_line_cursor#19 main::$6 ] ) always clobbers reg byte a +Statement [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) [ main::j#2 print_char_cursor#46 print_line_cursor#19 print_sword::w#1 ] ( main:2 [ main::j#2 print_char_cursor#46 print_line_cursor#19 print_sword::w#1 ] ) always clobbers reg byte a +Statement [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 [ main::j#1 print_char_cursor#56 print_line_cursor#1 ] ( main:2 [ main::j#1 print_char_cursor#56 print_line_cursor#1 ] ) always clobbers reg byte a +Statement [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 [ print_line_cursor#1 print_char_cursor#12 ] ( main:2::print_ln:22 [ main::j#2 print_line_cursor#1 print_char_cursor#12 ] ) always clobbers reg byte a +Statement [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 [ print_line_cursor#1 print_char_cursor#12 ] ( main:2::print_ln:22 [ main::j#2 print_line_cursor#1 print_char_cursor#12 ] ) always clobbers reg byte a +Statement [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 [ print_char_cursor#46 print_sword::w#1 ] ( main:2::print_sword:20 [ main::j#2 print_line_cursor#19 print_char_cursor#46 print_sword::w#1 ] ) always clobbers reg byte a +Statement [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 [ print_char_cursor#12 print_sword::w#0 ] ( main:2::print_sword:20 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_sword::w#0 ] ) always clobbers reg byte a +Statement [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 [ print_sword::w#3 print_char_cursor#41 print_byte::b#0 ] ( main:2::print_sword:20::print_word:37 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#41 print_byte::b#0 ] ) always clobbers reg byte a +Statement [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 [ print_char_cursor#12 print_byte::b#1 ] ( main:2::print_sword:20::print_word:37 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_byte::b#1 ] ) always clobbers reg byte a +Statement [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 [ print_byte::b#2 print_char_cursor#44 print_byte::$0 ] ( main:2::print_sword:20::print_word:37::print_byte:40 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_byte::b#2 print_char_cursor#44 print_byte::$0 ] main:2::print_sword:20::print_word:37::print_byte:42 [ main::j#2 print_line_cursor#19 print_byte::b#2 print_char_cursor#44 print_byte::$0 ] ) always clobbers reg byte a +Statement [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f [ print_char_cursor#12 print_byte::$2 ] ( main:2::print_sword:20::print_word:37::print_byte:40 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#12 print_byte::$2 ] main:2::print_sword:20::print_word:37::print_byte:42 [ main::j#2 print_line_cursor#19 print_char_cursor#12 print_byte::$2 ] ) always clobbers reg byte a +Statement [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 [ print_char_cursor#32 ] ( main:2::print_sword:20::print_char:34 [ main::j#2 print_line_cursor#19 print_sword::w#1 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:40::print_char:47 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_byte::b#2 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:42::print_char:47 [ main::j#2 print_line_cursor#19 print_byte::b#2 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:40::print_char:50 [ main::j#2 print_line_cursor#19 print_sword::w#3 print_char_cursor#32 ] main:2::print_sword:20::print_word:37::print_byte:42::print_char:50 [ main::j#2 print_line_cursor#19 print_char_cursor#32 ] ) always clobbers reg byte y +Statement [58] *((byte*) print_cls::sc#2) ← (byte) ' ' [ print_cls::sc#2 ] ( main:2::print_cls:16 [ print_cls::sc#2 ] ) always clobbers reg byte a reg byte y +Statement [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 [ print_cls::sc#1 ] ( main:2::print_cls:16 [ print_cls::sc#1 ] ) always clobbers reg byte a +Statement [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 [ ] ( main:2::sub:8 [ main::i#2 main::idx#0 ] main:2::sub:10 [ main::i#2 main::idx#0 ] main:2::sub:12 [ main::i#2 ] ) always clobbers reg byte a +Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:3 [ main::j#2 main::j#1 ] : zp ZP_BYTE:3 , reg byte x , +Potential registers zp ZP_WORD:4 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] : zp ZP_WORD:4 , +Potential registers zp ZP_WORD:6 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] : zp ZP_WORD:6 , +Potential registers zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] : zp ZP_BYTE:8 , reg byte x , +Potential registers zp ZP_BYTE:9 [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] : zp ZP_BYTE:9 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_WORD:10 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] : zp ZP_WORD:10 , +Potential registers zp ZP_WORD:12 [ print_cls::sc#2 print_cls::sc#1 ] : zp ZP_WORD:12 , +Potential registers zp ZP_BYTE:14 [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] : zp ZP_BYTE:14 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:15 [ sub::s#3 ] : zp ZP_BYTE:15 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:16 [ main::idx#0 ] : zp ZP_BYTE:16 , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:17 [ main::$6 ] : zp ZP_BYTE:17 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:18 [ print_byte::$0 ] : zp ZP_BYTE:18 , reg byte a , reg byte x , reg byte y , +Potential registers zp ZP_BYTE:19 [ print_byte::$2 ] : zp ZP_BYTE:19 , reg byte a , reg byte x , reg byte y , + +REGISTER UPLIFT SCOPES +Uplift Scope [] 252.6: zp ZP_WORD:4 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] 40.19: zp ZP_WORD:10 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +Uplift Scope [sub] 103: zp ZP_BYTE:14 [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] 2: zp ZP_BYTE:15 [ sub::s#3 ] +Uplift Scope [main] 22: zp ZP_BYTE:17 [ main::$6 ] 20.62: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 16.5: zp ZP_BYTE:3 [ main::j#2 main::j#1 ] 8.8: zp ZP_BYTE:16 [ main::idx#0 ] +Uplift Scope [print_cls] 33: zp ZP_WORD:12 [ print_cls::sc#2 print_cls::sc#1 ] +Uplift Scope [print_byte] 10: zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] 4: zp ZP_BYTE:18 [ print_byte::$0 ] 4: zp ZP_BYTE:19 [ print_byte::$2 ] +Uplift Scope [print_char] 14: zp ZP_BYTE:9 [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +Uplift Scope [print_sword] 9.58: zp ZP_WORD:6 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +Uplift Scope [print_ln] +Uplift Scope [print_word] + +Uplifting [] best 6617 combination zp ZP_WORD:4 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] zp ZP_WORD:10 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +Uplifting [sub] best 6518 combination reg byte x [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] reg byte a [ sub::s#3 ] +Uplifting [main] best 6178 combination reg byte a [ main::$6 ] reg byte y [ main::i#2 main::i#1 ] reg byte x [ main::j#2 main::j#1 ] reg byte x [ main::idx#0 ] +Uplifting [print_cls] best 6178 combination zp ZP_WORD:12 [ print_cls::sc#2 print_cls::sc#1 ] +Uplifting [print_byte] best 6170 combination zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] reg byte a [ print_byte::$0 ] reg byte a [ print_byte::$2 ] +Uplifting [print_char] best 6158 combination reg byte a [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +Uplifting [print_sword] best 6158 combination zp ZP_WORD:6 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +Uplifting [print_ln] best 6158 combination +Uplifting [print_word] best 6158 combination +Attempting to uplift remaining variables inzp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Uplifting [print_byte] best 6158 combination zp ZP_BYTE:8 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Coalescing zero page register [ zp ZP_WORD:4 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 ] ] with [ zp ZP_WORD:12 [ print_cls::sc#2 print_cls::sc#1 ] ] +Allocated (was zp ZP_WORD:4) zp ZP_WORD:2 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 print_cls::sc#2 print_cls::sc#1 ] +Allocated (was zp ZP_WORD:6) zp ZP_WORD:4 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +Allocated (was zp ZP_BYTE:8) zp ZP_BYTE:6 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +Allocated (was zp ZP_WORD:10) zp ZP_WORD:7 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] + +ASSEMBLER BEFORE OPTIMIZATION +//SEG0 File Comments +// Tests that signed indexed subtract works as intended +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(bbegin) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label print_line_cursor = 2 + .label print_char_cursor = 7 +//SEG3 @begin +bbegin: +//SEG4 [1] phi from @begin to @21 [phi:@begin->@21] +b21_from_bbegin: + jmp b21 +//SEG5 @21 +b21: +//SEG6 [2] call main +//SEG7 [4] phi from @21 to main [phi:@21->main] +main_from_b21: + jsr main +//SEG8 [3] phi from @21 to @end [phi:@21->@end] +bend_from_b21: + jmp bend +//SEG9 @end +bend: +//SEG10 main +main: { + //SEG11 [5] phi from main to main::@1 [phi:main->main::@1] + b1_from_main: + //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 + ldy #0 + jmp b1 + //SEG13 [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1] + b1_from_b7: + //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#0] -- register_copy + jmp b1 + //SEG15 main::@1 + b1: + //SEG16 [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuyy_rol_1 + tya + asl + tax + //SEG17 [7] (byte) sub::idx#0 ← (byte) main::idx#0 + //SEG18 [8] call sub + //SEG19 [62] phi from main::@1 to sub [phi:main::@1->sub] + sub_from_b1: + //SEG20 [62] phi (byte) sub::s#3 = (byte/word/signed word/dword/signed dword) $80 [phi:main::@1->sub#0] -- vbuaa=vbuc1 + lda #$80 + //SEG21 [62] phi (byte) sub::idx#3 = (byte) sub::idx#0 [phi:main::@1->sub#1] -- register_copy + jsr sub + jmp b5 + //SEG22 main::@5 + b5: + //SEG23 [9] (byte) sub::idx#1 ← (byte) main::idx#0 + //SEG24 [10] call sub + //SEG25 [62] phi from main::@5 to sub [phi:main::@5->sub] + sub_from_b5: + //SEG26 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@5->sub#0] -- vbuaa=vbuc1 + lda #$40 + //SEG27 [62] phi (byte) sub::idx#3 = (byte) sub::idx#1 [phi:main::@5->sub#1] -- register_copy + jsr sub + jmp b6 + //SEG28 main::@6 + b6: + //SEG29 [11] (byte) sub::idx#2 ← (byte) main::idx#0 + //SEG30 [12] call sub + //SEG31 [62] phi from main::@6 to sub [phi:main::@6->sub] + sub_from_b6: + //SEG32 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@6->sub#0] -- vbuaa=vbuc1 + lda #$40 + //SEG33 [62] phi (byte) sub::idx#3 = (byte) sub::idx#2 [phi:main::@6->sub#1] -- register_copy + jsr sub + jmp b7 + //SEG34 main::@7 + b7: + //SEG35 [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy + iny + //SEG36 [14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 + cpy #9 + bne b1_from_b7 + //SEG37 [15] phi from main::@7 to main::@3 [phi:main::@7->main::@3] + b3_from_b7: + jmp b3 + //SEG38 main::@3 + b3: + //SEG39 [16] call print_cls + //SEG40 [56] phi from main::@3 to print_cls [phi:main::@3->print_cls] + print_cls_from_b3: + jsr print_cls + //SEG41 [17] phi from main::@3 to main::@2 [phi:main::@3->main::@2] + b2_from_b3: + //SEG42 [17] phi (byte*) print_line_cursor#19 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 + lda #<$400 + sta print_line_cursor + lda #>$400 + sta print_line_cursor+1 + //SEG43 [17] phi (byte*) print_char_cursor#46 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#1] -- pbuz1=pbuc1 + lda #<$400 + sta print_char_cursor + lda #>$400 + sta print_char_cursor+1 + //SEG44 [17] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#2] -- vbuxx=vbuc1 + ldx #0 + jmp b2 + //SEG45 main::@2 + b2: + //SEG46 [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_rol_1 + txa + asl + //SEG47 [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) -- vwsz1=pwsc1_derefidx_vbuaa + tay + lda words,y + sta print_sword.w + lda words+1,y + sta print_sword.w+1 + //SEG48 [20] call print_sword + jsr print_sword + //SEG49 [21] phi from main::@2 to main::@9 [phi:main::@2->main::@9] + b9_from_b2: + jmp b9 + //SEG50 main::@9 + b9: + //SEG51 [22] call print_ln + //SEG52 [27] phi from main::@9 to print_ln [phi:main::@9->print_ln] + print_ln_from_b9: + jsr print_ln + jmp b10 + //SEG53 main::@10 + b10: + //SEG54 [23] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx + inx + //SEG55 [24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12 -- vbuxx_neq_vbuc1_then_la1 + cpx #9 + bne b12 + jmp breturn + //SEG56 main::@return + breturn: + //SEG57 [25] return + rts + //SEG58 main::@12 + b12: + //SEG59 [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 -- pbuz1=pbuz2 + lda print_line_cursor + sta print_char_cursor + lda print_line_cursor+1 + sta print_char_cursor+1 + //SEG60 [17] phi from main::@12 to main::@2 [phi:main::@12->main::@2] + b2_from_b12: + //SEG61 [17] phi (byte*) print_line_cursor#19 = (byte*) print_line_cursor#1 [phi:main::@12->main::@2#0] -- register_copy + //SEG62 [17] phi (byte*) print_char_cursor#46 = (byte*~) print_char_cursor#56 [phi:main::@12->main::@2#1] -- register_copy + //SEG63 [17] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@12->main::@2#2] -- register_copy + jmp b2 +} +//SEG64 print_ln +// Print a newline +print_ln: { + //SEG65 [28] phi from print_ln print_ln::@1 to print_ln::@1 [phi:print_ln/print_ln::@1->print_ln::@1] + b1_from_print_ln: + b1_from_b1: + //SEG66 [28] phi (byte*) print_line_cursor#9 = (byte*) print_line_cursor#19 [phi:print_ln/print_ln::@1->print_ln::@1#0] -- register_copy + jmp b1 + //SEG67 print_ln::@1 + b1: + //SEG68 [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 -- pbuz1=pbuz1_plus_vbuc1 + lda print_line_cursor + clc + adc #$28 + sta print_line_cursor + bcc !+ + inc print_line_cursor+1 + !: + //SEG69 [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 -- pbuz1_lt_pbuz2_then_la1 + lda print_line_cursor+1 + cmp print_char_cursor+1 + bcc b1_from_b1 + bne !+ + lda print_line_cursor + cmp print_char_cursor + bcc b1_from_b1 + !: + jmp breturn + //SEG70 print_ln::@return + breturn: + //SEG71 [31] return + rts +} +//SEG72 print_sword +// Print a signed word as HEX +// print_sword(signed word zeropage(4) w) +print_sword: { + .label w = 4 + //SEG73 [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 -- vwsz1_ge_0_then_la1 + lda w+1 + bpl b1_from_print_sword + //SEG74 [33] phi from print_sword to print_sword::@2 [phi:print_sword->print_sword::@2] + b2_from_print_sword: + jmp b2 + //SEG75 print_sword::@2 + b2: + //SEG76 [34] call print_char + //SEG77 [52] phi from print_sword::@2 to print_char [phi:print_sword::@2->print_char] + print_char_from_b2: + //SEG78 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#46 [phi:print_sword::@2->print_char#0] -- register_copy + //SEG79 [52] phi (byte) print_char::ch#3 = (byte) '-' [phi:print_sword::@2->print_char#1] -- vbuaa=vbuc1 + lda #'-' + jsr print_char + jmp b4 + //SEG80 print_sword::@4 + b4: + //SEG81 [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 -- vwsz1=_neg_vwsz1 + sec + lda w + eor #$ff + adc #0 + sta w + lda w+1 + eor #$ff + adc #0 + sta w+1 + //SEG82 [36] phi from print_sword print_sword::@4 to print_sword::@1 [phi:print_sword/print_sword::@4->print_sword::@1] + b1_from_print_sword: + b1_from_b4: + //SEG83 [36] phi (byte*) print_char_cursor#41 = (byte*) print_char_cursor#46 [phi:print_sword/print_sword::@4->print_sword::@1#0] -- register_copy + //SEG84 [36] phi (signed word) print_sword::w#3 = (signed word) print_sword::w#1 [phi:print_sword/print_sword::@4->print_sword::@1#1] -- register_copy + jmp b1 + //SEG85 print_sword::@1 + b1: + //SEG86 [37] call print_word + jsr print_word + jmp breturn + //SEG87 print_sword::@return + breturn: + //SEG88 [38] return + rts +} +//SEG89 print_word +// Print a word as HEX +print_word: { + //SEG90 [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 -- vbuz1=_hi_vwuz2 + lda print_sword.w+1 + sta print_byte.b + //SEG91 [40] call print_byte + //SEG92 [44] phi from print_word to print_byte [phi:print_word->print_byte] + print_byte_from_print_word: + //SEG93 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#41 [phi:print_word->print_byte#0] -- register_copy + //SEG94 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#0 [phi:print_word->print_byte#1] -- register_copy + jsr print_byte + jmp b1 + //SEG95 print_word::@1 + b1: + //SEG96 [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 -- vbuz1=_lo_vwuz2 + lda print_sword.w + sta print_byte.b + //SEG97 [42] call print_byte + //SEG98 [44] phi from print_word::@1 to print_byte [phi:print_word::@1->print_byte] + print_byte_from_b1: + //SEG99 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#12 [phi:print_word::@1->print_byte#0] -- register_copy + //SEG100 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#1 [phi:print_word::@1->print_byte#1] -- register_copy + jsr print_byte + jmp breturn + //SEG101 print_word::@return + breturn: + //SEG102 [43] return + rts +} +//SEG103 print_byte +// Print a byte as HEX +// print_byte(byte zeropage(6) b) +print_byte: { + .label b = 6 + //SEG104 [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 -- vbuaa=vbuz1_ror_4 + lda b + lsr + lsr + lsr + lsr + //SEG105 [46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) -- vbuaa=pbuc1_derefidx_vbuaa + tay + lda print_hextab,y + //SEG106 [47] call print_char + //SEG107 [52] phi from print_byte to print_char [phi:print_byte->print_char] + print_char_from_print_byte: + //SEG108 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#44 [phi:print_byte->print_char#0] -- register_copy + //SEG109 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#1 [phi:print_byte->print_char#1] -- register_copy + jsr print_char + jmp b1 + //SEG110 print_byte::@1 + b1: + //SEG111 [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f -- vbuaa=vbuz1_band_vbuc1 + lda #$f + and b + //SEG112 [49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) -- vbuaa=pbuc1_derefidx_vbuaa + tay + lda print_hextab,y + //SEG113 [50] call print_char + //SEG114 [52] phi from print_byte::@1 to print_char [phi:print_byte::@1->print_char] + print_char_from_b1: + //SEG115 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#12 [phi:print_byte::@1->print_char#0] -- register_copy + //SEG116 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#2 [phi:print_byte::@1->print_char#1] -- register_copy + jsr print_char + jmp breturn + //SEG117 print_byte::@return + breturn: + //SEG118 [51] return + rts +} +//SEG119 print_char +// Print a single char +// print_char(byte register(A) ch) +print_char: { + //SEG120 [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 -- _deref_pbuz1=vbuaa + ldy #0 + sta (print_char_cursor),y + //SEG121 [54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 -- pbuz1=_inc_pbuz1 + inc print_char_cursor + bne !+ + inc print_char_cursor+1 + !: + jmp breturn + //SEG122 print_char::@return + breturn: + //SEG123 [55] return + rts +} +//SEG124 print_cls +// Clear the screen. Also resets current line/char cursor. +print_cls: { + .label sc = 2 + //SEG125 [57] phi from print_cls to print_cls::@1 [phi:print_cls->print_cls::@1] + b1_from_print_cls: + //SEG126 [57] phi (byte*) print_cls::sc#2 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:print_cls->print_cls::@1#0] -- pbuz1=pbuc1 + lda #<$400 + sta sc + lda #>$400 + sta sc+1 + jmp b1 + //SEG127 [57] phi from print_cls::@1 to print_cls::@1 [phi:print_cls::@1->print_cls::@1] + b1_from_b1: + //SEG128 [57] phi (byte*) print_cls::sc#2 = (byte*) print_cls::sc#1 [phi:print_cls::@1->print_cls::@1#0] -- register_copy + jmp b1 + //SEG129 print_cls::@1 + b1: + //SEG130 [58] *((byte*) print_cls::sc#2) ← (byte) ' ' -- _deref_pbuz1=vbuc1 + lda #' ' + ldy #0 + sta (sc),y + //SEG131 [59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 -- pbuz1=_inc_pbuz1 + inc sc + bne !+ + inc sc+1 + !: + //SEG132 [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 -- pbuz1_neq_pbuc1_then_la1 + lda sc+1 + cmp #>$400+$3e8 + bne b1_from_b1 + lda sc + cmp #<$400+$3e8 + bne b1_from_b1 + jmp breturn + //SEG133 print_cls::@return + breturn: + //SEG134 [61] return + rts +} +//SEG135 sub +// sub(byte register(X) idx, byte register(A) s) +sub: { + //SEG136 [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 -- pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa + clc + sbc words,x + eor #$ff + sta words,x + bcc !+ + lda words+1,x + sbc #1 + sta words+1,x + !: + jmp breturn + //SEG137 sub::@return + breturn: + //SEG138 [64] return + rts +} + print_hextab: .text "0123456789abcdef" + words: .word -$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp b21 +Removing instruction jmp bend +Removing instruction jmp b1 +Removing instruction jmp b5 +Removing instruction jmp b6 +Removing instruction jmp b7 +Removing instruction jmp b3 +Removing instruction jmp b2 +Removing instruction jmp b9 +Removing instruction jmp b10 +Removing instruction jmp breturn +Removing instruction jmp b1 +Removing instruction jmp breturn +Removing instruction jmp b2 +Removing instruction jmp b4 +Removing instruction jmp b1 +Removing instruction jmp breturn +Removing instruction jmp b1 +Removing instruction jmp breturn +Removing instruction jmp b1 +Removing instruction jmp breturn +Removing instruction jmp breturn +Removing instruction jmp b1 +Removing instruction jmp breturn +Removing instruction jmp breturn +Succesful ASM optimization Pass5NextJumpElimination +Replacing label b1_from_b7 with b1 +Replacing label b1_from_b1 with b1 +Replacing label b1_from_b1 with b1 +Replacing label b1_from_print_sword with b1 +Replacing label b1_from_b1 with b1 +Replacing label b1_from_b1 with b1 +Removing instruction b21_from_bbegin: +Removing instruction b21: +Removing instruction main_from_b21: +Removing instruction bend_from_b21: +Removing instruction b1_from_b7: +Removing instruction sub_from_b5: +Removing instruction sub_from_b6: +Removing instruction b3_from_b7: +Removing instruction print_cls_from_b3: +Removing instruction b9_from_b2: +Removing instruction print_ln_from_b9: +Removing instruction b1_from_print_ln: +Removing instruction b1_from_b1: +Removing instruction b2_from_print_sword: +Removing instruction print_char_from_b2: +Removing instruction b1_from_print_sword: +Removing instruction b1_from_b4: +Removing instruction b1_from_b1: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction bend: +Removing instruction b1_from_main: +Removing instruction sub_from_b1: +Removing instruction b5: +Removing instruction b6: +Removing instruction b7: +Removing instruction b3: +Removing instruction b2_from_b3: +Removing instruction b9: +Removing instruction b10: +Removing instruction breturn: +Removing instruction b2_from_b12: +Removing instruction breturn: +Removing instruction b2: +Removing instruction b4: +Removing instruction breturn: +Removing instruction print_byte_from_print_word: +Removing instruction b1: +Removing instruction print_byte_from_b1: +Removing instruction breturn: +Removing instruction print_char_from_print_byte: +Removing instruction b1: +Removing instruction print_char_from_b1: +Removing instruction breturn: +Removing instruction breturn: +Removing instruction b1_from_print_cls: +Removing instruction breturn: +Removing instruction breturn: +Succesful ASM optimization Pass5UnusedLabelElimination +Updating BasicUpstart to call main directly +Removing instruction jsr main +Succesful ASM optimization Pass5SkipBegin +Removing instruction jmp b1 +Removing instruction jmp b1 +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction bbegin: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(label) @21 +(label) @begin +(label) @end +(void()) main() +(byte~) main::$6 reg byte a 22.0 +(label) main::@1 +(label) main::@10 +(label) main::@12 +(label) main::@2 +(label) main::@3 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@9 +(label) main::@return +(byte) main::i +(byte) main::i#1 reg byte y 16.5 +(byte) main::i#2 reg byte y 4.125 +(byte) main::idx +(byte) main::idx#0 reg byte x 8.8 +(byte) main::j +(byte) main::j#1 reg byte x 11.0 +(byte) main::j#2 reg byte x 5.5 +(void()) print_byte((byte) print_byte::b) +(byte~) print_byte::$0 reg byte a 4.0 +(byte~) print_byte::$2 reg byte a 4.0 +(label) print_byte::@1 +(label) print_byte::@return +(byte) print_byte::b +(byte) print_byte::b#0 b zp ZP_BYTE:6 4.0 +(byte) print_byte::b#1 b zp ZP_BYTE:6 4.0 +(byte) print_byte::b#2 b zp ZP_BYTE:6 2.0 +(void()) print_char((byte) print_char::ch) +(label) print_char::@return +(byte) print_char::ch +(byte) print_char::ch#1 reg byte a 4.0 +(byte) print_char::ch#2 reg byte a 4.0 +(byte) print_char::ch#3 reg byte a 6.0 +(byte*) print_char_cursor +(byte*) print_char_cursor#12 print_char_cursor zp ZP_WORD:7 5.190476190476189 +(byte*) print_char_cursor#32 print_char_cursor zp ZP_WORD:7 5.0 +(byte*) print_char_cursor#41 print_char_cursor zp ZP_WORD:7 3.0 +(byte*) print_char_cursor#44 print_char_cursor zp ZP_WORD:7 2.0 +(byte*) print_char_cursor#46 print_char_cursor zp ZP_WORD:7 3.0 +(byte*~) print_char_cursor#56 print_char_cursor zp ZP_WORD:7 22.0 +(void()) print_cls() +(label) print_cls::@1 +(label) print_cls::@return +(byte*) print_cls::sc +(byte*) print_cls::sc#1 sc zp ZP_WORD:2 16.5 +(byte*) print_cls::sc#2 sc zp ZP_WORD:2 16.5 +(byte[]) print_hextab +(const byte[]) print_hextab#0 print_hextab = (string) "0123456789abcdef" +(byte*) print_line_cursor +(byte*) print_line_cursor#1 print_line_cursor zp ZP_WORD:2 46.42857142857143 +(byte*) print_line_cursor#19 print_line_cursor zp ZP_WORD:2 2.1666666666666665 +(byte*) print_line_cursor#9 print_line_cursor zp ZP_WORD:2 204.0 +(void()) print_ln() +(label) print_ln::@1 +(label) print_ln::@return +(byte*) print_screen +(void()) print_sword((signed word) print_sword::w) +(label) print_sword::@1 +(label) print_sword::@2 +(label) print_sword::@4 +(label) print_sword::@return +(signed word) print_sword::w +(signed word) print_sword::w#0 w zp ZP_WORD:4 4.0 +(signed word) print_sword::w#1 w zp ZP_WORD:4 4.25 +(signed word) print_sword::w#3 w zp ZP_WORD:4 1.3333333333333333 +(void()) print_word((word) print_word::w) +(label) print_word::@1 +(label) print_word::@return +(word) print_word::w +(void()) sub((byte) sub::idx , (byte) sub::s) +(label) sub::@return +(byte) sub::idx +(byte) sub::idx#0 reg byte x 22.0 +(byte) sub::idx#1 reg byte x 22.0 +(byte) sub::idx#2 reg byte x 22.0 +(byte) sub::idx#3 reg byte x 37.0 +(byte) sub::s +(byte) sub::s#3 reg byte a 2.0 +(signed word[]) words +(const signed word[]) words#0 words = { -(word/signed word/dword/signed dword) $6000, -(word/signed word/dword/signed dword) $600, -(byte/signed byte/word/signed word/dword/signed dword) $60, -(byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) $60, (word/signed word/dword/signed dword) $600, (word/signed word/dword/signed dword) $6000 } + +reg byte y [ main::i#2 main::i#1 ] +reg byte x [ main::j#2 main::j#1 ] +zp ZP_WORD:2 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 print_cls::sc#2 print_cls::sc#1 ] +zp ZP_WORD:4 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +zp ZP_BYTE:6 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +reg byte a [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +zp ZP_WORD:7 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +reg byte x [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] +reg byte a [ sub::s#3 ] +reg byte x [ main::idx#0 ] +reg byte a [ main::$6 ] +reg byte a [ print_byte::$0 ] +reg byte a [ print_byte::$2 ] + + +FINAL ASSEMBLER +Score: 5261 + +//SEG0 File Comments +// Tests that signed indexed subtract works as intended +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label print_line_cursor = 2 + .label print_char_cursor = 7 +//SEG3 @begin +//SEG4 [1] phi from @begin to @21 [phi:@begin->@21] +//SEG5 @21 +//SEG6 [2] call main +//SEG7 [4] phi from @21 to main [phi:@21->main] +//SEG8 [3] phi from @21 to @end [phi:@21->@end] +//SEG9 @end +//SEG10 main +main: { + //SEG11 [5] phi from main to main::@1 [phi:main->main::@1] + //SEG12 [5] phi (byte) main::i#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 + ldy #0 + //SEG13 [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1] + //SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#0] -- register_copy + //SEG15 main::@1 + b1: + //SEG16 [6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuxx=vbuyy_rol_1 + tya + asl + tax + //SEG17 [7] (byte) sub::idx#0 ← (byte) main::idx#0 + //SEG18 [8] call sub + //SEG19 [62] phi from main::@1 to sub [phi:main::@1->sub] + //SEG20 [62] phi (byte) sub::s#3 = (byte/word/signed word/dword/signed dword) $80 [phi:main::@1->sub#0] -- vbuaa=vbuc1 + lda #$80 + //SEG21 [62] phi (byte) sub::idx#3 = (byte) sub::idx#0 [phi:main::@1->sub#1] -- register_copy + jsr sub + //SEG22 main::@5 + //SEG23 [9] (byte) sub::idx#1 ← (byte) main::idx#0 + //SEG24 [10] call sub + //SEG25 [62] phi from main::@5 to sub [phi:main::@5->sub] + //SEG26 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@5->sub#0] -- vbuaa=vbuc1 + lda #$40 + //SEG27 [62] phi (byte) sub::idx#3 = (byte) sub::idx#1 [phi:main::@5->sub#1] -- register_copy + jsr sub + //SEG28 main::@6 + //SEG29 [11] (byte) sub::idx#2 ← (byte) main::idx#0 + //SEG30 [12] call sub + //SEG31 [62] phi from main::@6 to sub [phi:main::@6->sub] + //SEG32 [62] phi (byte) sub::s#3 = (byte/signed byte/word/signed word/dword/signed dword) $40 [phi:main::@6->sub#0] -- vbuaa=vbuc1 + lda #$40 + //SEG33 [62] phi (byte) sub::idx#3 = (byte) sub::idx#2 [phi:main::@6->sub#1] -- register_copy + jsr sub + //SEG34 main::@7 + //SEG35 [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy + iny + //SEG36 [14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 + cpy #9 + bne b1 + //SEG37 [15] phi from main::@7 to main::@3 [phi:main::@7->main::@3] + //SEG38 main::@3 + //SEG39 [16] call print_cls + //SEG40 [56] phi from main::@3 to print_cls [phi:main::@3->print_cls] + jsr print_cls + //SEG41 [17] phi from main::@3 to main::@2 [phi:main::@3->main::@2] + //SEG42 [17] phi (byte*) print_line_cursor#19 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#0] -- pbuz1=pbuc1 + lda #<$400 + sta print_line_cursor + lda #>$400 + sta print_line_cursor+1 + //SEG43 [17] phi (byte*) print_char_cursor#46 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:main::@3->main::@2#1] -- pbuz1=pbuc1 + lda #<$400 + sta print_char_cursor + lda #>$400 + sta print_char_cursor+1 + //SEG44 [17] phi (byte) main::j#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main::@3->main::@2#2] -- vbuxx=vbuc1 + ldx #0 + //SEG45 main::@2 + b2: + //SEG46 [18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1 -- vbuaa=vbuxx_rol_1 + txa + asl + //SEG47 [19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6) -- vwsz1=pwsc1_derefidx_vbuaa + tay + lda words,y + sta print_sword.w + lda words+1,y + sta print_sword.w+1 + //SEG48 [20] call print_sword + jsr print_sword + //SEG49 [21] phi from main::@2 to main::@9 [phi:main::@2->main::@9] + //SEG50 main::@9 + //SEG51 [22] call print_ln + //SEG52 [27] phi from main::@9 to print_ln [phi:main::@9->print_ln] + jsr print_ln + //SEG53 main::@10 + //SEG54 [23] (byte) main::j#1 ← ++ (byte) main::j#2 -- vbuxx=_inc_vbuxx + inx + //SEG55 [24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12 -- vbuxx_neq_vbuc1_then_la1 + cpx #9 + bne b12 + //SEG56 main::@return + //SEG57 [25] return + rts + //SEG58 main::@12 + b12: + //SEG59 [26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1 -- pbuz1=pbuz2 + lda print_line_cursor + sta print_char_cursor + lda print_line_cursor+1 + sta print_char_cursor+1 + //SEG60 [17] phi from main::@12 to main::@2 [phi:main::@12->main::@2] + //SEG61 [17] phi (byte*) print_line_cursor#19 = (byte*) print_line_cursor#1 [phi:main::@12->main::@2#0] -- register_copy + //SEG62 [17] phi (byte*) print_char_cursor#46 = (byte*~) print_char_cursor#56 [phi:main::@12->main::@2#1] -- register_copy + //SEG63 [17] phi (byte) main::j#2 = (byte) main::j#1 [phi:main::@12->main::@2#2] -- register_copy + jmp b2 +} +//SEG64 print_ln +// Print a newline +print_ln: { + //SEG65 [28] phi from print_ln print_ln::@1 to print_ln::@1 [phi:print_ln/print_ln::@1->print_ln::@1] + //SEG66 [28] phi (byte*) print_line_cursor#9 = (byte*) print_line_cursor#19 [phi:print_ln/print_ln::@1->print_ln::@1#0] -- register_copy + //SEG67 print_ln::@1 + b1: + //SEG68 [29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28 -- pbuz1=pbuz1_plus_vbuc1 + lda print_line_cursor + clc + adc #$28 + sta print_line_cursor + bcc !+ + inc print_line_cursor+1 + !: + //SEG69 [30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1 -- pbuz1_lt_pbuz2_then_la1 + lda print_line_cursor+1 + cmp print_char_cursor+1 + bcc b1 + bne !+ + lda print_line_cursor + cmp print_char_cursor + bcc b1 + !: + //SEG70 print_ln::@return + //SEG71 [31] return + rts +} +//SEG72 print_sword +// Print a signed word as HEX +// print_sword(signed word zeropage(4) w) +print_sword: { + .label w = 4 + //SEG73 [32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1 -- vwsz1_ge_0_then_la1 + lda w+1 + bpl b1 + //SEG74 [33] phi from print_sword to print_sword::@2 [phi:print_sword->print_sword::@2] + //SEG75 print_sword::@2 + //SEG76 [34] call print_char + //SEG77 [52] phi from print_sword::@2 to print_char [phi:print_sword::@2->print_char] + //SEG78 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#46 [phi:print_sword::@2->print_char#0] -- register_copy + //SEG79 [52] phi (byte) print_char::ch#3 = (byte) '-' [phi:print_sword::@2->print_char#1] -- vbuaa=vbuc1 + lda #'-' + jsr print_char + //SEG80 print_sword::@4 + //SEG81 [35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1 -- vwsz1=_neg_vwsz1 + sec + lda w + eor #$ff + adc #0 + sta w + lda w+1 + eor #$ff + adc #0 + sta w+1 + //SEG82 [36] phi from print_sword print_sword::@4 to print_sword::@1 [phi:print_sword/print_sword::@4->print_sword::@1] + //SEG83 [36] phi (byte*) print_char_cursor#41 = (byte*) print_char_cursor#46 [phi:print_sword/print_sword::@4->print_sword::@1#0] -- register_copy + //SEG84 [36] phi (signed word) print_sword::w#3 = (signed word) print_sword::w#1 [phi:print_sword/print_sword::@4->print_sword::@1#1] -- register_copy + //SEG85 print_sword::@1 + b1: + //SEG86 [37] call print_word + jsr print_word + //SEG87 print_sword::@return + //SEG88 [38] return + rts +} +//SEG89 print_word +// Print a word as HEX +print_word: { + //SEG90 [39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3 -- vbuz1=_hi_vwuz2 + lda print_sword.w+1 + sta print_byte.b + //SEG91 [40] call print_byte + //SEG92 [44] phi from print_word to print_byte [phi:print_word->print_byte] + //SEG93 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#41 [phi:print_word->print_byte#0] -- register_copy + //SEG94 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#0 [phi:print_word->print_byte#1] -- register_copy + jsr print_byte + //SEG95 print_word::@1 + //SEG96 [41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3 -- vbuz1=_lo_vwuz2 + lda print_sword.w + sta print_byte.b + //SEG97 [42] call print_byte + //SEG98 [44] phi from print_word::@1 to print_byte [phi:print_word::@1->print_byte] + //SEG99 [44] phi (byte*) print_char_cursor#44 = (byte*) print_char_cursor#12 [phi:print_word::@1->print_byte#0] -- register_copy + //SEG100 [44] phi (byte) print_byte::b#2 = (byte) print_byte::b#1 [phi:print_word::@1->print_byte#1] -- register_copy + jsr print_byte + //SEG101 print_word::@return + //SEG102 [43] return + rts +} +//SEG103 print_byte +// Print a byte as HEX +// print_byte(byte zeropage(6) b) +print_byte: { + .label b = 6 + //SEG104 [45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4 -- vbuaa=vbuz1_ror_4 + lda b + lsr + lsr + lsr + lsr + //SEG105 [46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0) -- vbuaa=pbuc1_derefidx_vbuaa + tay + lda print_hextab,y + //SEG106 [47] call print_char + //SEG107 [52] phi from print_byte to print_char [phi:print_byte->print_char] + //SEG108 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#44 [phi:print_byte->print_char#0] -- register_copy + //SEG109 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#1 [phi:print_byte->print_char#1] -- register_copy + jsr print_char + //SEG110 print_byte::@1 + //SEG111 [48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f -- vbuaa=vbuz1_band_vbuc1 + lda #$f + and b + //SEG112 [49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2) -- vbuaa=pbuc1_derefidx_vbuaa + tay + lda print_hextab,y + //SEG113 [50] call print_char + //SEG114 [52] phi from print_byte::@1 to print_char [phi:print_byte::@1->print_char] + //SEG115 [52] phi (byte*) print_char_cursor#32 = (byte*) print_char_cursor#12 [phi:print_byte::@1->print_char#0] -- register_copy + //SEG116 [52] phi (byte) print_char::ch#3 = (byte) print_char::ch#2 [phi:print_byte::@1->print_char#1] -- register_copy + jsr print_char + //SEG117 print_byte::@return + //SEG118 [51] return + rts +} +//SEG119 print_char +// Print a single char +// print_char(byte register(A) ch) +print_char: { + //SEG120 [53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3 -- _deref_pbuz1=vbuaa + ldy #0 + sta (print_char_cursor),y + //SEG121 [54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32 -- pbuz1=_inc_pbuz1 + inc print_char_cursor + bne !+ + inc print_char_cursor+1 + !: + //SEG122 print_char::@return + //SEG123 [55] return + rts +} +//SEG124 print_cls +// Clear the screen. Also resets current line/char cursor. +print_cls: { + .label sc = 2 + //SEG125 [57] phi from print_cls to print_cls::@1 [phi:print_cls->print_cls::@1] + //SEG126 [57] phi (byte*) print_cls::sc#2 = ((byte*))(word/signed word/dword/signed dword) $400 [phi:print_cls->print_cls::@1#0] -- pbuz1=pbuc1 + lda #<$400 + sta sc + lda #>$400 + sta sc+1 + //SEG127 [57] phi from print_cls::@1 to print_cls::@1 [phi:print_cls::@1->print_cls::@1] + //SEG128 [57] phi (byte*) print_cls::sc#2 = (byte*) print_cls::sc#1 [phi:print_cls::@1->print_cls::@1#0] -- register_copy + //SEG129 print_cls::@1 + b1: + //SEG130 [58] *((byte*) print_cls::sc#2) ← (byte) ' ' -- _deref_pbuz1=vbuc1 + lda #' ' + ldy #0 + sta (sc),y + //SEG131 [59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2 -- pbuz1=_inc_pbuz1 + inc sc + bne !+ + inc sc+1 + !: + //SEG132 [60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1 -- pbuz1_neq_pbuc1_then_la1 + lda sc+1 + cmp #>$400+$3e8 + bne b1 + lda sc + cmp #<$400+$3e8 + bne b1 + //SEG133 print_cls::@return + //SEG134 [61] return + rts +} +//SEG135 sub +// sub(byte register(X) idx, byte register(A) s) +sub: { + //SEG136 [63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3 -- pwsc1_derefidx_vbuxx=pwsc1_derefidx_vbuxx_minus_vbuaa + clc + sbc words,x + eor #$ff + sta words,x + bcc !+ + lda words+1,x + sbc #1 + sta words+1,x + !: + //SEG137 sub::@return + //SEG138 [64] return + rts +} + print_hextab: .text "0123456789abcdef" + words: .word -$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000 + diff --git a/src/test/ref/signed-indexed-subtract.sym b/src/test/ref/signed-indexed-subtract.sym new file mode 100644 index 000000000..62f0db719 --- /dev/null +++ b/src/test/ref/signed-indexed-subtract.sym @@ -0,0 +1,99 @@ +(label) @21 +(label) @begin +(label) @end +(void()) main() +(byte~) main::$6 reg byte a 22.0 +(label) main::@1 +(label) main::@10 +(label) main::@12 +(label) main::@2 +(label) main::@3 +(label) main::@5 +(label) main::@6 +(label) main::@7 +(label) main::@9 +(label) main::@return +(byte) main::i +(byte) main::i#1 reg byte y 16.5 +(byte) main::i#2 reg byte y 4.125 +(byte) main::idx +(byte) main::idx#0 reg byte x 8.8 +(byte) main::j +(byte) main::j#1 reg byte x 11.0 +(byte) main::j#2 reg byte x 5.5 +(void()) print_byte((byte) print_byte::b) +(byte~) print_byte::$0 reg byte a 4.0 +(byte~) print_byte::$2 reg byte a 4.0 +(label) print_byte::@1 +(label) print_byte::@return +(byte) print_byte::b +(byte) print_byte::b#0 b zp ZP_BYTE:6 4.0 +(byte) print_byte::b#1 b zp ZP_BYTE:6 4.0 +(byte) print_byte::b#2 b zp ZP_BYTE:6 2.0 +(void()) print_char((byte) print_char::ch) +(label) print_char::@return +(byte) print_char::ch +(byte) print_char::ch#1 reg byte a 4.0 +(byte) print_char::ch#2 reg byte a 4.0 +(byte) print_char::ch#3 reg byte a 6.0 +(byte*) print_char_cursor +(byte*) print_char_cursor#12 print_char_cursor zp ZP_WORD:7 5.190476190476189 +(byte*) print_char_cursor#32 print_char_cursor zp ZP_WORD:7 5.0 +(byte*) print_char_cursor#41 print_char_cursor zp ZP_WORD:7 3.0 +(byte*) print_char_cursor#44 print_char_cursor zp ZP_WORD:7 2.0 +(byte*) print_char_cursor#46 print_char_cursor zp ZP_WORD:7 3.0 +(byte*~) print_char_cursor#56 print_char_cursor zp ZP_WORD:7 22.0 +(void()) print_cls() +(label) print_cls::@1 +(label) print_cls::@return +(byte*) print_cls::sc +(byte*) print_cls::sc#1 sc zp ZP_WORD:2 16.5 +(byte*) print_cls::sc#2 sc zp ZP_WORD:2 16.5 +(byte[]) print_hextab +(const byte[]) print_hextab#0 print_hextab = (string) "0123456789abcdef" +(byte*) print_line_cursor +(byte*) print_line_cursor#1 print_line_cursor zp ZP_WORD:2 46.42857142857143 +(byte*) print_line_cursor#19 print_line_cursor zp ZP_WORD:2 2.1666666666666665 +(byte*) print_line_cursor#9 print_line_cursor zp ZP_WORD:2 204.0 +(void()) print_ln() +(label) print_ln::@1 +(label) print_ln::@return +(byte*) print_screen +(void()) print_sword((signed word) print_sword::w) +(label) print_sword::@1 +(label) print_sword::@2 +(label) print_sword::@4 +(label) print_sword::@return +(signed word) print_sword::w +(signed word) print_sword::w#0 w zp ZP_WORD:4 4.0 +(signed word) print_sword::w#1 w zp ZP_WORD:4 4.25 +(signed word) print_sword::w#3 w zp ZP_WORD:4 1.3333333333333333 +(void()) print_word((word) print_word::w) +(label) print_word::@1 +(label) print_word::@return +(word) print_word::w +(void()) sub((byte) sub::idx , (byte) sub::s) +(label) sub::@return +(byte) sub::idx +(byte) sub::idx#0 reg byte x 22.0 +(byte) sub::idx#1 reg byte x 22.0 +(byte) sub::idx#2 reg byte x 22.0 +(byte) sub::idx#3 reg byte x 37.0 +(byte) sub::s +(byte) sub::s#3 reg byte a 2.0 +(signed word[]) words +(const signed word[]) words#0 words = { -(word/signed word/dword/signed dword) $6000, -(word/signed word/dword/signed dword) $600, -(byte/signed byte/word/signed word/dword/signed dword) $60, -(byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) $60, (word/signed word/dword/signed dword) $600, (word/signed word/dword/signed dword) $6000 } + +reg byte y [ main::i#2 main::i#1 ] +reg byte x [ main::j#2 main::j#1 ] +zp ZP_WORD:2 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 print_cls::sc#2 print_cls::sc#1 ] +zp ZP_WORD:4 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ] +zp ZP_BYTE:6 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ] +reg byte a [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ] +zp ZP_WORD:7 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ] +reg byte x [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ] +reg byte a [ sub::s#3 ] +reg byte x [ main::idx#0 ] +reg byte a [ main::$6 ] +reg byte a [ print_byte::$0 ] +reg byte a [ print_byte::$2 ]