/
tos_scenarios.txt
56 lines (45 loc) · 2.62 KB
/
tos_scenarios.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Comparison of Top of Stack (TOS) Scenarios
Scot W. Stevenson <scot.stevenson@gmail.com>
First version: 09. Apr 2016
This version: 10. Apr 2016
Liara Forth can either place the first entry in the Forth Data Stack (the "Top
of Stack", TOS) in Direct Page (DP), in register Y (X is used for the Data
Stack Pointer, DSP), or the accumulator A. The following is a comparison of
common, native-coded ("primitive") Forth words for each of these scenarios. For
a summary, see the table at tos_variants.
The 65816 is assumed to be in native mode with all registers 16 bit wide. The
RTS instruction at the end is assumed, but not counted. Data Stack (DS) is in
direct page, with top entry (TOS for DP Scenario, NOS for Y and A regs) at
offset 00.
TOS DP TOS A REG TOS Y REG
=== ! ====================================================
lda.dx 02 2/5 tay 1/2 lda.dx 00 2/5
ldy.dx 00 2/5 lda.dx 00 2/5 sta.y 0000 3/6
sta.y 0000 3/6 sta.y 0000 3/6 ldy.dx 02 2/5
inx 1/2 lda.dx 02 2/5 inx 1/2
inx 1/2 inx 1/2 inx 1/2
inx 1/2 inx 1/2 inx 1/2
inx 1/2 inx 1/2 inx 1/2
inx 1/2
----- ------ -----
11/24 12/26 11/24
=== DROP =================================================
inx 1/2 lda.dx 00 2/5
inx 1/2 inx 1/2 ( as A but with ldy.dx)
inx 1/2
----- ----- -----
2/4 4/9 4/9
=== DUP ==================================================
lda.dx 00 2/5 dex 1/2
dex 1/2 dex 1/2 (as A but with sty.dx)
dex 1/2 sta.dx 00 2/5
sta.dx 00 2/5
----- ------ -----
6/14 4/9 4/9
=== SWAP =================================================
lda.dx 00 2/5 ldy.dx 00 2/5 lda.dx 00 2/5
ldy.dx 02 2/5 sta.dx 00 2/5 sty.dx 00 2/5
sta.dx 02 2/5 tya 1/2 tay 1/2
sty.dx 00 2/5
----- ----- -----
8/20 5/12 5/12