
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  printneg::c#0 = -4
  call printneg
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void printneg(signed char c)
printneg: scope:[printneg]  from main
  printneg::c#2 = phi( main/printneg::c#0 )
  printneg::$0 = - printneg::c#2
  printneg::c#1 = printneg::$0
  SCREEN[0] = printneg::c#1
  to:printneg::@return
printneg::@return: scope:[printneg]  from printneg
  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 signed char * const SCREEN = (signed char *)$400
void __start()
void main()
void printneg(signed char c)
signed char printneg::$0
signed char printneg::c
signed char printneg::c#0
signed char printneg::c#1
signed char printneg::c#2

Adding number conversion cast (snumber) -4 in printneg::c#0 = -4
Adding number conversion cast (unumber) 0 in SCREEN[0] = printneg::c#1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast printneg::c#0 = (snumber)-4
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (signed char *) 1024
Simplifying constant integer cast -4
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized signed number type (signed char) -4
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias printneg::c#1 = printneg::$0 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values printneg::c#2 printneg::c#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant printneg::c#0 = -4
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN in [5] SCREEN[0] = printneg::c#1
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
Constant right-side identified [2] printneg::c#1 = - printneg::c#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant printneg::c#1 = -printneg::c#0
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with different constant siblings printneg::c#0
Inlining constant with different constant siblings printneg::c#1
Constant inlined printneg::c#1 = --4
Constant inlined printneg::c#0 = -4
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
CALL GRAPH
Calls in [main] to printneg:1 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block label main::@1
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call printneg
  to:main::@return
main::@return: scope:[main]  from main
  [2] return 
  to:@return

void printneg(signed char c)
printneg: scope:[printneg]  from main
  [3] *SCREEN = --4
  to:printneg::@return
printneg::@return: scope:[printneg]  from printneg
  [4] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
void printneg(signed char c)
signed char printneg::c

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [3] *SCREEN = --4 [ ] ( printneg:1 [ ] { }  ) always clobbers reg byte a 

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

Uplifting [main] best 30 combination 
Uplifting [printneg] best 30 combination 
Uplifting [] best 30 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Illustrates problem with negating a constant negative number
// KickAsm requires parenthesis for double negation to work
  // Upstart
  // Commodore 64 PRG executable file
.file [name="problem-negate-const.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
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] call printneg
    jsr printneg
    jmp __breturn
    // main::@return
  __breturn:
    // [2] return 
    rts
}
  // printneg
// void printneg(signed char c)
printneg: {
    // [3] *SCREEN = --4 -- _deref_pbsc1=vbsc2 
    lda #-(-4)
    sta SCREEN
    jmp __breturn
    // printneg::@return
  __breturn:
    // [4] return 
    rts
}
  // File Data

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

FINAL SYMBOL TABLE
__constant signed char * const SCREEN = (signed char *) 1024
void main()
void printneg(signed char c)
signed char printneg::c



FINAL ASSEMBLER
Score: 24

  // File Comments
// Illustrates problem with negating a constant negative number
// KickAsm requires parenthesis for double negation to work
  // Upstart
  // Commodore 64 PRG executable file
.file [name="problem-negate-const.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
  .label SCREEN = $400
.segment Code
  // main
main: {
    // printneg(-4)
    // [1] call printneg
    jsr printneg
    // main::@return
    // }
    // [2] return 
    rts
}
  // printneg
// void printneg(signed char c)
printneg: {
    // SCREEN[0] = c
    // [3] *SCREEN = --4 -- _deref_pbsc1=vbsc2 
    lda #-(-4)
    sta SCREEN
    // printneg::@return
    // }
    // [4] return 
    rts
}
  // File Data

