aboutsummaryrefslogtreecommitdiffstats
path: root/asm/test_py_src.atk16
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-11-13 23:12:05 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2023-11-13 23:12:05 +0200
commit14d8401c721fae8367fa24db20af4e344faafdd4 (patch)
tree58931d22d9c903a15bbe137c571dd76c7a98799b /asm/test_py_src.atk16
parente2b7385b03a6dc9c8c39dde5c049cd74b0768bd1 (diff)
Fix calling issues
Diffstat (limited to 'asm/test_py_src.atk16')
-rw-r--r--asm/test_py_src.atk16285
1 files changed, 138 insertions, 147 deletions
diff --git a/asm/test_py_src.atk16 b/asm/test_py_src.atk16
index 2d8e311..b605dad 100644
--- a/asm/test_py_src.atk16
+++ b/asm/test_py_src.atk16
@@ -2,7 +2,9 @@
@use ext_std:*
-@let sp RH
+@let sp RH ; stack pointer (points to empty slot at top of stack)
+@let fp RG ; frame pointer (points to base of currently active frame)
+
@let vector_table 0x10
@let vt_ISR0 0x10 ; ISR0
@let vt_ISR1 0x11 ; ISR1
@@ -30,6 +32,7 @@
@address 0x0
ldi vt_stack_addr RA
ldr RA SP
+ mov SP FP
jpi program_segment
@address vector_table
@@ -77,47 +80,39 @@
23
@label text_mem_addr_p
25
-@label int_1
+@label int_0
65
-@label int_5
+@label int_6
26
-; <ast.FunctionDef object at 0x1048ce500>
+; <ast.FunctionDef object at 0x104f1f370>
@label nth_letter
; stack frame with offsets
-; return_address_0 3
-; n 4
-; <ast.Return object at 0x1048ce440>
-; <ast.Add object at 0x1045f6ad0>
-; BinOp lhs <ast.BinOp object at 0x1048ce410>
-; <ast.Name object at 0x1048ce3e0> (n)
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 4 RB
- add RA RB RA
- ldr RA RA
- spu RA
-; BinOp rhs <ast.BinOp object at 0x1048ce410>
-; <ast.Constant object at 0x1048ce3b0>
- ldi int_1 RA
- ldr RA RA
- spu RA
- spo RB
- spo RA
- add RA RB RA
- spu RA
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 3 RB
- add RA RB RA
-; stack address of return address is stored in reg RA
- spo RB
-; return value is stored in reg RB
- mov RA SP
- ldr RA RA
- spu RB
+; n 0
+; <ast.Return object at 0x104f1f430>
+; <ast.Add object at 0x104ed2c20>
+; BinOp lhs <ast.BinOp object at 0x1051b52a0>
+; <ast.Call object at 0x1051b5270>
+; Builtin call ord [<ast.Constant object at 0x1051b51e0>]
+; <ast.Constant object at 0x1051b51e0>
+ ldi int_0 RC
+ ldr RC RC ; int_0 = 65
+ spu RC
+; BinOp rhs <ast.BinOp object at 0x1051b52a0>
+; <ast.Name object at 0x1051b51b0> (n)
+ ldi 0 RC
+ add FP RC RC
+ ldr RC RC
+ spu RC
+ spo RD
+ spo RC
+ add RC RD RC
+ spu RC
+; return value is on top of stack
; return from function
- jpr RA
+ subi FP 1 FP
+ ldr FP RB
+ jpr RB
@label main
; stack frame with offsets
@@ -125,186 +120,182 @@
; text_mem_addr 1
; i 2
addi SP 3 SP
-; <ast.Assign object at 0x1048ce860>
-; assigning graphics_mode_addr at stack segment + 0
+; <ast.Assign object at 0x104f1ffd0>
+; assigning graphics_mode_addr at FP + 0
; evaluating value to be assigned
-; <ast.Call object at 0x1048ce800>
-; Builtin call load [<ast.Name object at 0x1048ce770>]
-; <ast.Name object at 0x1048ce770> (GRAPHICS_MODE_ADDR_P)
+; <ast.Call object at 0x104f1fa00>
+; Builtin call load [<ast.Name object at 0x104f1f970>]
+; <ast.Name object at 0x104f1f970> (GRAPHICS_MODE_ADDR_P)
ldi graphics_mode_addr_p RC
ldr RC RC
spu RC
+; (load) dereferencing top of stack
spo RC
ldr RC RC
spu RC
-; assigning value to stack segment + 0
- ldi vt_stack_addr RA
- ldr RA RA
+; assigning stack address (FP + 0) := top of stack
+ spo RA
ldi 0 RB
- add RA RB RA
- spo RB
- str RB RA
-; <ast.Assign object at 0x1048ce740>
-; assigning text_mem_addr at stack segment + 1
+ add RB FP RB
+ str RA RB
+; <ast.Assign object at 0x104f1f940>
+; assigning text_mem_addr at FP + 1
; evaluating value to be assigned
-; <ast.Call object at 0x1048ce6e0>
-; Builtin call load [<ast.Name object at 0x1048ce650>]
-; <ast.Name object at 0x1048ce650> (TEXT_MEM_ADDR_P)
+; <ast.Call object at 0x104f1f610>
+; Builtin call load [<ast.Name object at 0x104f1f550>]
+; <ast.Name object at 0x104f1f550> (TEXT_MEM_ADDR_P)
ldi text_mem_addr_p RC
ldr RC RC
spu RC
+; (load) dereferencing top of stack
spo RC
ldr RC RC
spu RC
-; assigning value to stack segment + 1
- ldi vt_stack_addr RA
- ldr RA RA
+; assigning stack address (FP + 1) := top of stack
+ spo RA
ldi 1 RB
- add RA RB RA
- spo RB
- str RB RA
-; <ast.Call object at 0x1048ce5f0>
-; Builtin call store [<ast.Name object at 0x1048ce560>, <ast.Name object at 0x1048ce530>]
-; <ast.Name object at 0x1048ce560> (graphics_mode_addr)
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 0 RB
- add RA RB RA
+ add RB FP RB
+ str RA RB
+; <ast.Call object at 0x104f1f4f0>
+; Builtin call store [<ast.Name object at 0x104f1f3d0>, <ast.Name object at 0x104f1f3a0>]
+; <ast.Name object at 0x104f1f3d0> (graphics_mode_addr)
+ ldi 0 RA
+ add FP RA RA
ldr RA RA
spu RA
-; <ast.Name object at 0x1048ce530> (TEXT_MODE)
+; <ast.Name object at 0x104f1f3a0> (TEXT_MODE)
ldi text_mode RA
ldr RA RA
spu RA
spo RB
spo RA
str RB RA
-; <ast.Assign object at 0x1048ce350>
-; assigning i at stack segment + 2
+ ldi 0 RA
+ spu RA
+; popping free-standing Expr result from stack
+ spo RA
+; <ast.Assign object at 0x1051b5150>
+; assigning i at FP + 2
; evaluating value to be assigned
-; <ast.Constant object at 0x1048ce2f0>
+; <ast.Constant object at 0x1051b50f0>
ldi 0 RC
spu RC
-; assigning value to stack segment + 2
- ldi vt_stack_addr RA
- ldr RA RA
+; assigning stack address (FP + 2) := top of stack
+ spo RA
ldi 2 RB
- add RA RB RA
- spo RB
- str RB RA
-; <ast.Call object at 0x1048ce290>
-; Builtin call asm [<ast.Constant object at 0x1048ce200>]
- ldi 0b111111111 RG
-; <ast.While object at 0x1048ce1d0>
-@label while_test_2
-; <ast.Name object at 0x1048ce170> (i)
- ldi vt_stack_addr RB
- ldr RB RB
- ldi 2 RC
- add RB RC RB
+ add RB FP RB
+ str RA RB
+; <ast.While object at 0x1051b50c0>
+@label while_test_1
+; <ast.Compare object at 0x1051b5090>
+; <ast.Name object at 0x1051b5060> (i)
+ ldi 2 RB
+ add FP RB RB
ldr RB RB
spu RB
-; <ast.Constant object at 0x1048ce140>
- ldi int_5 RB
- ldr RB RB
+; <ast.Constant object at 0x1051b5030>
+ ldi int_6 RB
+ ldr RB RB ; int_6 = 26
spu RB
+; Comparing <ast.Name object at 0x1051b5060> <ast.Lt object at 0x104ed2470> <ast.Constant object at 0x1051b5030>
spo RC
spo RB
sub RB RC RB
- bri carry Compare_true_6
+ bri carry Compare_true_4
ldi 0 RB
spu RB
- jpi Compare_end_7
-@label compare_true_6
+ jpi Compare_end_5
+@label compare_true_4
ldi 1 RB
spu RB
-@label compare_end_7
+@label compare_end_5
spo RA
addi RA 0 RA
- bri zero While_else_3
-; <ast.Call object at 0x1048ce0e0>
-; Builtin call store [<ast.BinOp object at 0x1048ce050>, <ast.Call object at 0x1048cdd80>]
-; <ast.Add object at 0x1045f6ad0>
-; BinOp lhs <ast.BinOp object at 0x1048ce050>
-; <ast.Name object at 0x1048ce020> (text_mem_addr)
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 1 RB
- add RA RB RA
+ bri zero While_else_2
+; <ast.Call object at 0x1051b4fd0>
+; Builtin call store [<ast.BinOp object at 0x1051b4f40>, <ast.Call object at 0x1051b4eb0>]
+; <ast.Add object at 0x104ed2c20>
+; BinOp lhs <ast.BinOp object at 0x1051b4f40>
+; <ast.Name object at 0x1051b4f10> (text_mem_addr)
+ ldi 1 RA
+ add FP RA RA
ldr RA RA
spu RA
-; BinOp rhs <ast.BinOp object at 0x1048ce050>
-; <ast.Name object at 0x1048cdff0> (i)
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 2 RB
- add RA RB RA
+; BinOp rhs <ast.BinOp object at 0x1051b4f40>
+; <ast.Name object at 0x1051b4ee0> (i)
+ ldi 2 RA
+ add FP RA RA
ldr RA RA
spu RA
spo RB
spo RA
add RA RB RA
spu RA
-; <ast.Call object at 0x1048cdd80>
+; <ast.Call object at 0x1051b4eb0>
; Call function nth_letter
+ spu FP
ldi 0 RA
spu RA
-; <ast.Name object at 0x1048cdd20> (i)
- ldi vt_stack_addr RA
- ldr RA RA
- ldi 2 RB
- add RA RB RA
+; <ast.Name object at 0x1051b4e50> (i)
+ ldi 2 RA
+ add FP RA RA
ldr RA RA
spu RA
+ subi SP 2 FP
; set up return address and jump to subroutine
- subi SP 2 RA
- lpc RB
- addi RB 3 RB
- str RB RA
+ lpc RA
+ addi RA 4 RA
+ str RA FP
+ addi FP 1 FP
jpi nth_letter
+ spo RA
+ mov FP SP
+ spo FP
+ spu RA
spo RB
spo RA
str RB RA
-; <ast.Assign object at 0x1048ccc70>
-; assigning i at stack segment + 2
+ ldi 0 RA
+ spu RA
+; popping free-standing Expr result from stack
+ spo RA
+; <ast.Assign object at 0x1051b4e20>
+; assigning i at FP + 2
; evaluating value to be assigned
-; <ast.Add object at 0x1045f6ad0>
-; BinOp lhs <ast.BinOp object at 0x1048cda50>
-; <ast.Name object at 0x1048cd750> (i)
- ldi vt_stack_addr RC
- ldr RC RC
- ldi 2 RD
- add RC RD RC
+; <ast.Add object at 0x104ed2c20>
+; BinOp lhs <ast.BinOp object at 0x1051b4dc0>
+; <ast.Name object at 0x1051b4d90> (i)
+ ldi 2 RC
+ add FP RC RC
ldr RC RC
spu RC
-; BinOp rhs <ast.BinOp object at 0x1048cda50>
-; <ast.Constant object at 0x1048cd720>
+; BinOp rhs <ast.BinOp object at 0x1051b4dc0>
+; <ast.Constant object at 0x1051b4d60>
ldi 1 RC
spu RC
spo RD
spo RC
add RC RD RC
spu RC
-; assigning value to stack segment + 2
- ldi vt_stack_addr RA
- ldr RA RA
+; assigning stack address (FP + 2) := top of stack
+ spo RA
ldi 2 RB
- add RA RB RA
- spo RB
- str RB RA
- jpi While_test_2
-@label while_else_3
-@label while_end_4
-; <ast.While object at 0x1048cd0f0>
-@label while_test_8
-; <ast.Constant object at 0x1048cd060>
+ add RB FP RB
+ str RA RB
+ jpi While_test_1
+@label while_else_2
+@label while_end_3
+; <ast.While object at 0x1051b4d30>
+@label while_test_7
+; <ast.Constant object at 0x1051b4d00>
ldi 1 RB
spu RB
spo RA
addi RA 0 RA
- bri zero While_else_9
-; <ast.Pass object at 0x1048ccfa0>
- jpi While_test_8
-@label while_else_9
-@label while_end_10
- subi SP 3 SP
+ bri zero While_else_8
+; <ast.Pass object at 0x1051b4cd0>
+ jpi While_test_7
+@label while_else_8
+@label while_end_9
+ mov FP SP
+ hlt