-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.s
169 lines (137 loc) · 2.08 KB
/
main.s
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
.include "macros.i"
# "REGISTERS"
.text
.set TOS, %r15
.set TOSB, %r15b
.set SP, %r14
.set IP, %r13
.set WP, %r12
.set ACC, %r11
.set ACCB, %r11b
.set CMD, %rax
.set ARGA, %rdi
.set ARGB, %rsi
.set ARGC, %rdx
.set ARGD, %r10
.set ARGE, %r8
.set ARGF, %r9
# Kernel
.global _start
_start: movq %rsp, rspbk
mov $_cold, IP
next:
mov (IP), WP
advance IP
mov $0x0000FFFFFFFFFFFF, ACC
and (WP), ACC # Strip flags off the codefield
jmp *ACC
enter:
push IP
mov WP, IP
advance IP
jmp next
# "DICTIONARY"
.data
.quad 0
7: strlit "COLD"
COLD: forthword
_cold: do RESETDATA
set LAST dictionaryhead
set here dictionaryend
escape 0
escape 96
saycr "aFORTH alpha"
set numtib 0
do QUIT
verb forth ABORT
do RESETDATA
do QUIT
verb forth QUIT
do RESETRETURN # was commented out?
do modeI
2: do TIB
const 256 #80
escape 93
say "> "
do ACCEPT
escape 0
test equal 0 1f
set numtib
do INTERPRET
goto 2b
1: escape 96
saycr "Done."
escape 0
do HALT
.include "stack.s"
.include "memory.s"
.include "boolean.s"
.include "maths.s"
.include "input.s"
.include "dictionary.s"
.include "interpreter.s"
.include "compiler.s"
.include "output.s"
.include "extras.s"
# "CODEWORDS"
verb code HALT
_halt: xor ARGA, ARGA # default return code 0
sub $stack, SP
jz 1f
mov TOS, ARGA
1: mov $60, CMD # system call 60 is exit
syscall
# Do Stuff
docon: codeword
_dup
mov (IP), TOS
advance IP
jmp next
dovar: codeword
_dup
mov IP, TOS
advance IP
jmp next
dostr: codeword
_dup
mov IP, TOS
add (IP), IP
advance IP
jmp next
dogoto: codeword
mov (IP), IP
jmp next
dobranch: codeword
minstk 1
cmp $0, TOS
je __brk
mov (IP), IP
jmp _drop
__brk: advance IP
jmp _drop
dountil: codeword
minstk 1
cmp $0, TOS
jne __brk
sub (IP), IP
jmp _drop
# Kernel
verb code EXIT
pop IP
jmp next
dictionaryhead:
verb code EXECUTE
minstk 1
mov TOS, WP
mov (SP), TOS
advance SP
mov $0x0000FFFFFFFFFFFF, ACC
and (WP), ACC # Strip flags off the codefield
jmp *ACC
dictionaryend:
# "STACK"
.skip 1048576
stack: .quad 0
# "CORE VARIABLES"
rspbk: .quad 0
buff: .quad 0