<h1><h1>
1 |; -- Start --
2 |CONST 4
3 |CALL Square
4 |HALT
5 |;
6 |; This function squares the preceding value
7 |Square:
8 |LOAD -3
9 |LOAD -3
10 |CALL Mul
11 |STORE -3
12 |RET
13 |;
14 |; This function multiplies the preceding two values
15 |Mul:
16 |ALLOC 3
17 |CONST 0
18 |STORE 0
19 |LOAD -3
20 |STORE 1
21 |LOAD -4
22 |STORE 2
23 |Loop:
24 |LOAD 0
25 |LOAD 1
26 |ADD
27 |STORE 0
28 |LOAD 2
29 |CONST 1
30 |SUB
31 |FJUMP End
32 |ALLOC 1
33 |STORE 2
34 |JUMP Loop
35 |End:
36 |LOAD 0
37 |STORE -3
38 |RET