
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  SCREEN[0] = byte0 (unsigned int)DVAL/$400
  SCREEN[1] = byte1 (unsigned int)DVAL/$400
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant const unsigned long DVAL = $20000
__constant char * const SCREEN = (char *)$400
void __start()
void main()

Adding number conversion cast (unumber) $400 in SCREEN[0] = byte0 (unsigned int)DVAL/$400
Adding number conversion cast (unumber) 0 in SCREEN[0] = byte0 (unsigned int)DVAL/(unumber)$400
Adding number conversion cast (unumber) $400 in SCREEN[1] = byte1 (unsigned int)DVAL/$400
Adding number conversion cast (unumber) 1 in SCREEN[1] = byte1 (unsigned int)DVAL/(unumber)$400
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $400
Simplifying constant integer cast 0
Simplifying constant integer cast $400
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (unsigned int) $400
Finalized unsigned number type (char) 0
Finalized unsigned number type (unsigned int) $400
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant evaluating to zero byte1 (unsigned int)DVAL/$400 in [1] SCREEN[1] = byte1 (unsigned int)DVAL/$400
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero SCREEN in [0] SCREEN[0] = byte0 (unsigned int)DVAL/$400
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Consolidated array index constant in *(SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *SCREEN = byte0 (unsigned int)DVAL/$400
  [1] *(SCREEN+1) = 0
  to:main::@return
main::@return: scope:[main]  from main
  [2] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *SCREEN = byte0 (unsigned int)DVAL/$400 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *(SCREEN+1) = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 21 combination 
Uplifting [] best 21 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Illustrates problem with constant evaluation of lo/hi-operator
// $20000 /$400 results in a byte value - confusing the lo/hi-evaluation
// which currently relies on getting the type from the literal value.
// A fix could be adding support for "declared" types for constant literal values
// - enabling the lo/hi to know that their operand is a word (from the cast).
  // Upstart
  // Commodore 64 PRG executable file
.file [name="operator-lohi-problem-1.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const DVAL = $20000
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [0] *SCREEN = byte0 (unsigned int)DVAL/$400 -- _deref_pbuc1=vbuc2 
    lda #<DVAL/$400
    sta SCREEN
    // [1] *(SCREEN+1) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta SCREEN+1
    jmp __breturn
    // main::@return
  __breturn:
    // [2] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant const unsigned long DVAL = $20000
__constant char * const SCREEN = (char *) 1024
void main()



FINAL ASSEMBLER
Score: 18

  // File Comments
// Illustrates problem with constant evaluation of lo/hi-operator
// $20000 /$400 results in a byte value - confusing the lo/hi-evaluation
// which currently relies on getting the type from the literal value.
// A fix could be adding support for "declared" types for constant literal values
// - enabling the lo/hi to know that their operand is a word (from the cast).
  // Upstart
  // Commodore 64 PRG executable file
.file [name="operator-lohi-problem-1.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const DVAL = $20000
  .label SCREEN = $400
.segment Code
  // main
main: {
    // SCREEN[0] = BYTE0((word)(DVAL/$400))
    // [0] *SCREEN = byte0 (unsigned int)DVAL/$400 -- _deref_pbuc1=vbuc2 
    lda #<DVAL/$400
    sta SCREEN
    // SCREEN[1] = BYTE1((word)(DVAL/$400))
    // [1] *(SCREEN+1) = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta SCREEN+1
    // main::@return
    // }
    // [2] return 
    rts
}
  // File Data

