2020-11-22 21:30:24 +00:00
|
|
|
Calling convention __stackcall adding prepare/execute/finalize for main::$0 = call plus $1234 $2345
|
2020-10-05 20:58:02 +00:00
|
|
|
Calling convention STACK_CALL replacing param(plus::a) with stackidx(word,plus::OFFSET_STACK_A)
|
|
|
|
Calling convention STACK_CALL replacing param(plus::b) with stackidx(word,plus::OFFSET_STACK_B)
|
|
|
|
Calling convention STACK_CALL adding stack return stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return
|
|
|
|
Calling convention STACK_CALL adding stack pull main::$0 = stackpull(word)
|
|
|
|
Calling convention STACK_CALL adding stack push stackpush(word) = $1234
|
|
|
|
Calling convention STACK_CALL adding stack push stackpush(word) = $2345
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
void main()
|
2020-06-27 20:36:52 +00:00
|
|
|
main: scope:[main] from __start
|
2020-10-05 20:58:02 +00:00
|
|
|
stackpush(word) = $1234
|
|
|
|
stackpush(word) = $2345
|
2020-03-05 08:13:52 +00:00
|
|
|
callexecute plus
|
2020-10-05 20:58:02 +00:00
|
|
|
sideeffect stackpullbytes(2)
|
|
|
|
main::$0 = stackpull(word)
|
|
|
|
main::$1 = 0 * SIZEOF_WORD
|
|
|
|
SCREEN[main::$1] = main::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main
|
|
|
|
return
|
|
|
|
to:@return
|
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
__stackcall word plus(word plus::a , word plus::b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: scope:[plus] from
|
2020-10-05 20:58:02 +00:00
|
|
|
plus::a#0 = stackidx(word,plus::OFFSET_STACK_A)
|
|
|
|
plus::b#0 = stackidx(word,plus::OFFSET_STACK_B)
|
|
|
|
plus::$0 = plus::a#0 + plus::b#0
|
|
|
|
plus::return#0 = plus::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:plus::@return
|
|
|
|
plus::@return: scope:[plus] from plus
|
2020-10-05 20:58:02 +00:00
|
|
|
plus::return#1 = phi( plus/plus::return#0 )
|
|
|
|
stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return#1
|
2020-03-06 23:33:07 +00:00
|
|
|
return
|
2019-09-20 14:27:50 +00:00
|
|
|
to:@return
|
2020-06-27 19:18:00 +00:00
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
void __start()
|
2020-06-27 20:36:52 +00:00
|
|
|
__start: scope:[__start] from
|
2019-09-20 14:27:50 +00:00
|
|
|
call main
|
2020-06-27 20:36:52 +00:00
|
|
|
to:__start::@1
|
|
|
|
__start::@1: scope:[__start] from __start
|
|
|
|
to:__start::@return
|
|
|
|
__start::@return: scope:[__start] from __start::@1
|
2020-06-27 19:18:00 +00:00
|
|
|
return
|
|
|
|
to:@return
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
SYMBOL TABLE SSA
|
2020-10-05 20:58:02 +00:00
|
|
|
const nomodify word* SCREEN = (word*)$400
|
|
|
|
const byte SIZEOF_WORD = 2
|
|
|
|
const word STACK_BASE = $103
|
|
|
|
void __start()
|
|
|
|
void main()
|
|
|
|
word~ main::$0
|
|
|
|
number~ main::$1
|
|
|
|
__stackcall word plus(word plus::a , word plus::b)
|
|
|
|
word~ plus::$0
|
|
|
|
const byte plus::OFFSET_STACK_A = 2
|
|
|
|
const byte plus::OFFSET_STACK_B = 0
|
|
|
|
const byte plus::OFFSET_STACK_RETURN = 2
|
|
|
|
word plus::a
|
|
|
|
word plus::a#0
|
|
|
|
word plus::b
|
|
|
|
word plus::b#0
|
|
|
|
word plus::return
|
|
|
|
word plus::return#0
|
|
|
|
word plus::return#1
|
2019-09-20 14:27:50 +00:00
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
Adding number conversion cast (unumber) $1234 in stackpush(word) = $1234
|
|
|
|
Adding number conversion cast (unumber) $2345 in stackpush(word) = $2345
|
|
|
|
Adding number conversion cast (unumber) 0 in main::$1 = 0 * SIZEOF_WORD
|
|
|
|
Adding number conversion cast (unumber) main::$1 in main::$1 = (unumber)0 * SIZEOF_WORD
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
2020-10-05 20:58:02 +00:00
|
|
|
Inlining cast stackpush(word) = (unumber)$1234
|
|
|
|
Inlining cast stackpush(word) = (unumber)$2345
|
2020-03-07 07:44:02 +00:00
|
|
|
Successful SSA optimization Pass2InlineCast
|
2019-09-20 14:27:50 +00:00
|
|
|
Simplifying constant pointer cast (word*) 1024
|
|
|
|
Simplifying constant integer cast $1234
|
|
|
|
Simplifying constant integer cast $2345
|
|
|
|
Simplifying constant integer cast 0
|
|
|
|
Successful SSA optimization PassNCastSimplification
|
2020-12-11 23:01:15 +00:00
|
|
|
Finalized unsigned number type (word) $1234
|
|
|
|
Finalized unsigned number type (word) $2345
|
|
|
|
Finalized unsigned number type (byte) 0
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
2020-10-05 20:58:02 +00:00
|
|
|
Inferred type updated to byte in main::$1 = 0 * SIZEOF_WORD
|
2020-03-22 21:26:39 +00:00
|
|
|
Alias plus::return#0 = plus::$0 plus::return#1
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization Pass2AliasElimination
|
2020-10-05 20:58:02 +00:00
|
|
|
Constant right-side identified [5] main::$1 = 0 * SIZEOF_WORD
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization Pass2ConstantRValueConsolidation
|
2020-10-05 20:58:02 +00:00
|
|
|
Constant main::$1 = 0*SIZEOF_WORD
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization Pass2ConstantIdentification
|
2020-10-05 20:58:02 +00:00
|
|
|
Simplifying constant evaluating to zero 0*SIZEOF_WORD in
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNSimplifyConstantZero
|
2020-10-05 20:58:02 +00:00
|
|
|
Simplifying expression containing zero SCREEN in [6] SCREEN[main::$1] = main::$0
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
2020-10-05 20:58:02 +00:00
|
|
|
Eliminating unused constant main::$1
|
|
|
|
Eliminating unused constant SIZEOF_WORD
|
2019-09-20 14:27:50 +00:00
|
|
|
Successful SSA optimization PassNEliminateUnusedVars
|
2020-06-27 20:36:52 +00:00
|
|
|
Removing unused procedure __start
|
|
|
|
Removing unused procedure block __start
|
|
|
|
Removing unused procedure block __start::@1
|
|
|
|
Removing unused procedure block __start::@return
|
2020-06-27 19:18:00 +00:00
|
|
|
Successful SSA optimization PassNEliminateEmptyStart
|
2020-12-11 23:01:15 +00:00
|
|
|
Finalized unsigned number type (byte) 2
|
|
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
2019-09-20 14:27:50 +00:00
|
|
|
CALL GRAPH
|
2020-03-07 07:44:02 +00:00
|
|
|
Calls in [main] to plus:7
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
Created 0 initial phi equivalence classes
|
|
|
|
Coalesced down to 0 phi equivalence classes
|
|
|
|
|
|
|
|
FINAL CONTROL FLOW GRAPH
|
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
__stackcall word plus(word plus::a , word plus::b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: scope:[plus] from
|
2020-10-05 20:58:02 +00:00
|
|
|
[0] plus::a#0 = stackidx(word,plus::OFFSET_STACK_A)
|
|
|
|
[1] plus::b#0 = stackidx(word,plus::OFFSET_STACK_B)
|
|
|
|
[2] plus::return#0 = plus::a#0 + plus::b#0
|
2019-09-20 14:27:50 +00:00
|
|
|
to:plus::@return
|
|
|
|
plus::@return: scope:[plus] from plus
|
2020-10-05 20:58:02 +00:00
|
|
|
[3] stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return#0
|
2020-06-27 19:18:00 +00:00
|
|
|
[4] return
|
|
|
|
to:@return
|
|
|
|
|
2020-10-05 20:58:02 +00:00
|
|
|
void main()
|
2020-06-27 19:18:00 +00:00
|
|
|
main: scope:[main] from
|
2020-10-05 20:58:02 +00:00
|
|
|
[5] stackpush(word) = $1234
|
|
|
|
[6] stackpush(word) = $2345
|
2020-06-27 19:18:00 +00:00
|
|
|
[7] callexecute plus
|
2020-10-05 20:58:02 +00:00
|
|
|
sideeffect stackpullbytes(2)
|
|
|
|
[9] main::$0 = stackpull(word)
|
|
|
|
[10] *SCREEN = main::$0
|
2020-06-27 19:18:00 +00:00
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main
|
|
|
|
[11] return
|
2019-09-20 14:27:50 +00:00
|
|
|
to:@return
|
|
|
|
|
|
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
2020-10-05 20:58:02 +00:00
|
|
|
void main()
|
|
|
|
word~ main::$0 4.0
|
|
|
|
__stackcall word plus(word plus::a , word plus::b)
|
|
|
|
word plus::a
|
|
|
|
word plus::a#0 11.0
|
|
|
|
word plus::b
|
|
|
|
word plus::b#0 22.0
|
|
|
|
word plus::return
|
|
|
|
word plus::return#0 22.0
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
Initial phi equivalence classes
|
2019-12-08 15:04:35 +00:00
|
|
|
Added variable plus::a#0 to live range equivalence class [ plus::a#0 ]
|
|
|
|
Added variable plus::b#0 to live range equivalence class [ plus::b#0 ]
|
|
|
|
Added variable plus::return#0 to live range equivalence class [ plus::return#0 ]
|
2020-06-27 19:18:00 +00:00
|
|
|
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
2019-09-20 14:27:50 +00:00
|
|
|
Complete equivalence classes
|
|
|
|
[ plus::a#0 ]
|
|
|
|
[ plus::b#0 ]
|
|
|
|
[ plus::return#0 ]
|
2020-06-27 19:18:00 +00:00
|
|
|
[ main::$0 ]
|
|
|
|
Allocated zp[2]:2 [ plus::a#0 ]
|
|
|
|
Allocated zp[2]:4 [ plus::b#0 ]
|
|
|
|
Allocated zp[2]:6 [ plus::return#0 ]
|
|
|
|
Allocated zp[2]:8 [ main::$0 ]
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
2020-10-05 20:58:02 +00:00
|
|
|
Statement [0] plus::a#0 = stackidx(word,plus::OFFSET_STACK_A) [ plus::a#0 ] ( plus:7 [ plus::a#0 ] { } ) always clobbers reg byte a reg byte x
|
|
|
|
Statement [1] plus::b#0 = stackidx(word,plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( plus:7 [ plus::a#0 plus::b#0 ] { } ) always clobbers reg byte a reg byte x
|
|
|
|
Statement [2] plus::return#0 = plus::a#0 + plus::b#0 [ plus::return#0 ] ( plus:7 [ plus::return#0 ] { } ) always clobbers reg byte a
|
|
|
|
Statement [3] stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return#0 [ ] ( plus:7 [ ] { } ) always clobbers reg byte a reg byte x
|
|
|
|
Statement [5] stackpush(word) = $1234 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
|
|
Statement [6] stackpush(word) = $2345 [ ] ( [ ] { } ) always clobbers reg byte a
|
|
|
|
Statement sideeffect stackpullbytes(2) always clobbers reg byte a
|
|
|
|
Statement [9] main::$0 = stackpull(word) [ main::$0 ] ( [ main::$0 ] { } ) always clobbers reg byte a
|
|
|
|
Statement [10] *SCREEN = main::$0 [ ] ( [ ] { } ) always clobbers reg byte a
|
2020-06-27 19:18:00 +00:00
|
|
|
Potential registers zp[2]:2 [ plus::a#0 ] : zp[2]:2 ,
|
|
|
|
Potential registers zp[2]:4 [ plus::b#0 ] : zp[2]:4 ,
|
|
|
|
Potential registers zp[2]:6 [ plus::return#0 ] : zp[2]:6 ,
|
|
|
|
Potential registers zp[2]:8 [ main::$0 ] : zp[2]:8 ,
|
|
|
|
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
|
|
Uplift Scope [plus] 22: zp[2]:4 [ plus::b#0 ] 22: zp[2]:6 [ plus::return#0 ] 11: zp[2]:2 [ plus::a#0 ]
|
|
|
|
Uplift Scope [main] 4: zp[2]:8 [ main::$0 ]
|
|
|
|
Uplift Scope []
|
|
|
|
|
|
|
|
Uplifting [plus] best 152 combination zp[2]:4 [ plus::b#0 ] zp[2]:6 [ plus::return#0 ] zp[2]:2 [ plus::a#0 ]
|
|
|
|
Uplifting [main] best 152 combination zp[2]:8 [ main::$0 ]
|
|
|
|
Uplifting [] best 152 combination
|
|
|
|
Coalescing zero page register [ zp[2]:2 [ plus::a#0 ] ] with [ zp[2]:6 [ plus::return#0 ] ] - score: 1
|
|
|
|
Coalescing zero page register [ zp[2]:8 [ main::$0 ] ] with [ zp[2]:2 [ plus::a#0 plus::return#0 ] ]
|
|
|
|
Allocated (was zp[2]:4) zp[2]:2 [ plus::b#0 ]
|
|
|
|
Allocated (was zp[2]:8) zp[2]:4 [ main::$0 plus::a#0 plus::return#0 ]
|
|
|
|
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
|
|
// File Comments
|
|
|
|
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
|
|
|
|
// Upstart
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// Global Constants & labels
|
|
|
|
.const STACK_BASE = $103
|
|
|
|
.label SCREEN = $400
|
2019-09-20 14:27:50 +00:00
|
|
|
// plus
|
2020-06-27 19:18:00 +00:00
|
|
|
// plus(word zp(4) a, word zp(2) b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: {
|
2020-02-27 12:26:30 +00:00
|
|
|
.const OFFSET_STACK_A = 2
|
|
|
|
.const OFFSET_STACK_B = 0
|
2019-09-23 15:53:23 +00:00
|
|
|
.const OFFSET_STACK_RETURN = 2
|
2020-03-08 22:26:49 +00:00
|
|
|
.label a = 4
|
2020-06-27 19:18:00 +00:00
|
|
|
.label b = 2
|
2020-03-08 22:26:49 +00:00
|
|
|
.label return = 4
|
2020-10-05 20:58:02 +00:00
|
|
|
// [0] plus::a#0 = stackidx(word,plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
|
|
sta.z a
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A+1,x
|
|
|
|
sta.z a+1
|
2020-10-05 20:58:02 +00:00
|
|
|
// [1] plus::b#0 = stackidx(word,plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
|
|
sta.z b
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B+1,x
|
|
|
|
sta.z b+1
|
2020-10-05 20:58:02 +00:00
|
|
|
// [2] plus::return#0 = plus::a#0 + plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z return
|
|
|
|
clc
|
|
|
|
adc.z b
|
|
|
|
sta.z return
|
|
|
|
lda.z return+1
|
|
|
|
adc.z b+1
|
|
|
|
sta.z return+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __breturn
|
2019-09-20 14:27:50 +00:00
|
|
|
// plus::@return
|
2019-09-29 21:13:37 +00:00
|
|
|
__breturn:
|
2020-10-05 20:58:02 +00:00
|
|
|
// [3] stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return#0 -- _stackidxword_vbuc1=vwuz1
|
2019-09-22 22:10:44 +00:00
|
|
|
tsx
|
|
|
|
lda.z return
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
2019-09-22 22:10:44 +00:00
|
|
|
lda.z return+1
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
|
2020-06-27 19:18:00 +00:00
|
|
|
// [4] return
|
|
|
|
rts
|
|
|
|
}
|
|
|
|
// main
|
|
|
|
main: {
|
|
|
|
.label __0 = 4
|
2020-10-05 20:58:02 +00:00
|
|
|
// [5] stackpush(word) = $1234 -- _stackpushword_=vwuc1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda #>$1234
|
|
|
|
pha
|
|
|
|
lda #<$1234
|
|
|
|
pha
|
2020-10-05 20:58:02 +00:00
|
|
|
// [6] stackpush(word) = $2345 -- _stackpushword_=vwuc1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda #>$2345
|
|
|
|
pha
|
|
|
|
lda #<$2345
|
|
|
|
pha
|
|
|
|
// [7] callexecute plus -- jsr
|
|
|
|
jsr plus
|
2020-10-05 20:58:02 +00:00
|
|
|
// sideeffect stackpullbytes(2) -- _stackpullbyte_2
|
2020-06-27 19:18:00 +00:00
|
|
|
pla
|
|
|
|
pla
|
2020-10-05 20:58:02 +00:00
|
|
|
// [9] main::$0 = stackpull(word) -- vwuz1=_stackpullword_
|
2020-06-27 19:18:00 +00:00
|
|
|
pla
|
|
|
|
sta.z __0
|
|
|
|
pla
|
|
|
|
sta.z __0+1
|
2020-10-05 20:58:02 +00:00
|
|
|
// [10] *SCREEN = main::$0 -- _deref_pwuc1=vwuz1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda.z __0
|
|
|
|
sta SCREEN
|
|
|
|
lda.z __0+1
|
|
|
|
sta SCREEN+1
|
|
|
|
jmp __breturn
|
|
|
|
// main::@return
|
|
|
|
__breturn:
|
|
|
|
// [11] return
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// File Data
|
|
|
|
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
2019-09-29 21:13:37 +00:00
|
|
|
Removing instruction jmp __breturn
|
|
|
|
Removing instruction jmp __breturn
|
2019-09-20 14:27:50 +00:00
|
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
2019-09-29 21:13:37 +00:00
|
|
|
Removing instruction __breturn:
|
|
|
|
Removing instruction __breturn:
|
2019-09-20 14:27:50 +00:00
|
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
|
|
|
|
|
|
FINAL SYMBOL TABLE
|
2020-10-05 20:58:02 +00:00
|
|
|
const nomodify word* SCREEN = (word*) 1024
|
|
|
|
const word STACK_BASE = $103
|
|
|
|
void main()
|
|
|
|
word~ main::$0 zp[2]:4 4.0
|
|
|
|
__stackcall word plus(word plus::a , word plus::b)
|
|
|
|
const byte plus::OFFSET_STACK_A = 2
|
|
|
|
const byte plus::OFFSET_STACK_B = 0
|
|
|
|
const byte plus::OFFSET_STACK_RETURN = 2
|
|
|
|
word plus::a
|
|
|
|
word plus::a#0 a zp[2]:4 11.0
|
|
|
|
word plus::b
|
|
|
|
word plus::b#0 b zp[2]:2 22.0
|
|
|
|
word plus::return
|
|
|
|
word plus::return#0 return zp[2]:4 22.0
|
2019-09-20 14:27:50 +00:00
|
|
|
|
2020-06-27 19:18:00 +00:00
|
|
|
zp[2]:2 [ plus::b#0 ]
|
|
|
|
zp[2]:4 [ main::$0 plus::a#0 plus::return#0 ]
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
2019-09-22 22:10:44 +00:00
|
|
|
Score: 146
|
2019-09-20 14:27:50 +00:00
|
|
|
|
|
|
|
// File Comments
|
|
|
|
// Test a procedure with calling convention stack - and enough parameters to use fast ASM for cleaning stack
|
|
|
|
// Upstart
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// Global Constants & labels
|
|
|
|
.const STACK_BASE = $103
|
2020-04-30 20:15:59 +00:00
|
|
|
.label SCREEN = $400
|
2019-09-20 14:27:50 +00:00
|
|
|
// plus
|
2020-06-27 19:18:00 +00:00
|
|
|
// plus(word zp(4) a, word zp(2) b)
|
2019-09-20 14:27:50 +00:00
|
|
|
plus: {
|
2020-02-27 12:26:30 +00:00
|
|
|
.const OFFSET_STACK_A = 2
|
|
|
|
.const OFFSET_STACK_B = 0
|
2019-09-23 15:53:23 +00:00
|
|
|
.const OFFSET_STACK_RETURN = 2
|
2020-03-08 22:26:49 +00:00
|
|
|
.label a = 4
|
2020-06-27 19:18:00 +00:00
|
|
|
.label b = 2
|
2020-03-08 22:26:49 +00:00
|
|
|
.label return = 4
|
2020-06-27 19:18:00 +00:00
|
|
|
// }
|
2020-10-05 20:58:02 +00:00
|
|
|
// [0] plus::a#0 = stackidx(word,plus::OFFSET_STACK_A) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A,x
|
|
|
|
sta.z a
|
|
|
|
lda STACK_BASE+OFFSET_STACK_A+1,x
|
|
|
|
sta.z a+1
|
2020-10-05 20:58:02 +00:00
|
|
|
// [1] plus::b#0 = stackidx(word,plus::OFFSET_STACK_B) -- vwuz1=_stackidxword_vbuc1
|
2019-09-20 14:27:50 +00:00
|
|
|
tsx
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B,x
|
|
|
|
sta.z b
|
|
|
|
lda STACK_BASE+OFFSET_STACK_B+1,x
|
|
|
|
sta.z b+1
|
|
|
|
// return a+b;
|
2020-10-05 20:58:02 +00:00
|
|
|
// [2] plus::return#0 = plus::a#0 + plus::b#0 -- vwuz1=vwuz1_plus_vwuz2
|
2019-09-20 14:27:50 +00:00
|
|
|
lda.z return
|
|
|
|
clc
|
|
|
|
adc.z b
|
|
|
|
sta.z return
|
|
|
|
lda.z return+1
|
|
|
|
adc.z b+1
|
|
|
|
sta.z return+1
|
|
|
|
// plus::@return
|
|
|
|
// }
|
2020-10-05 20:58:02 +00:00
|
|
|
// [3] stackidx(word,plus::OFFSET_STACK_RETURN) = plus::return#0 -- _stackidxword_vbuc1=vwuz1
|
2019-09-22 22:10:44 +00:00
|
|
|
tsx
|
|
|
|
lda.z return
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN,x
|
2019-09-22 22:10:44 +00:00
|
|
|
lda.z return+1
|
2019-09-23 15:53:23 +00:00
|
|
|
sta STACK_BASE+OFFSET_STACK_RETURN+1,x
|
2020-06-27 19:18:00 +00:00
|
|
|
// [4] return
|
|
|
|
rts
|
|
|
|
}
|
|
|
|
// main
|
|
|
|
main: {
|
|
|
|
.label __0 = 4
|
|
|
|
// plus(0x1234, 0x2345)
|
2020-10-05 20:58:02 +00:00
|
|
|
// [5] stackpush(word) = $1234 -- _stackpushword_=vwuc1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda #>$1234
|
|
|
|
pha
|
|
|
|
lda #<$1234
|
|
|
|
pha
|
2020-10-05 20:58:02 +00:00
|
|
|
// [6] stackpush(word) = $2345 -- _stackpushword_=vwuc1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda #>$2345
|
|
|
|
pha
|
|
|
|
lda #<$2345
|
|
|
|
pha
|
|
|
|
// [7] callexecute plus -- jsr
|
|
|
|
jsr plus
|
2020-10-05 20:58:02 +00:00
|
|
|
// sideeffect stackpullbytes(2) -- _stackpullbyte_2
|
2020-06-27 19:18:00 +00:00
|
|
|
pla
|
|
|
|
pla
|
2020-10-05 20:58:02 +00:00
|
|
|
// [9] main::$0 = stackpull(word) -- vwuz1=_stackpullword_
|
2020-06-27 19:18:00 +00:00
|
|
|
pla
|
|
|
|
sta.z __0
|
|
|
|
pla
|
|
|
|
sta.z __0+1
|
|
|
|
// SCREEN[0] = plus(0x1234, 0x2345)
|
2020-10-05 20:58:02 +00:00
|
|
|
// [10] *SCREEN = main::$0 -- _deref_pwuc1=vwuz1
|
2020-06-27 19:18:00 +00:00
|
|
|
lda.z __0
|
|
|
|
sta SCREEN
|
|
|
|
lda.z __0+1
|
|
|
|
sta SCREEN+1
|
|
|
|
// main::@return
|
|
|
|
// }
|
|
|
|
// [11] return
|
2019-09-20 14:27:50 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// File Data
|
|
|
|
|