forked from kspalaiologos/cosmopolitan-sk
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsk-asm2bf.asm
184 lines (176 loc) · 2.96 KB
/
sk-asm2bf.asm
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
?AX=r3
?BX=r2
?CX=r5
?DX=r6
?EX=f2
?FX=f3
?GX=r1
?HX=r4
stk 38
org 0
&heap
db 2
&changed
$(
function def_inline(ins)
print("@" .. ins .. "_i\n" .. ins .. " GX, HX\nret\n")
end
function inline(ins, arg1, arg2)
print("mov GX, " .. arg1 .. "\nmov HX, " .. arg2 .. "\n")
call(ins .. "_i")
end
function inline_r(ins, arg1, arg2)
print("mov HX, " .. arg2 .. "\n")
call(ins .. "_i")
print("mov " .. arg1 .. ", GX")
end
)
#call("read")
@loop
#call("eval")
$(inline_r("rcl", "BX", "*changed"))
mov GX, *changed
mov HX, 0
#call("sto_i")
^jnz BX, %loop
^push 0
@P
^push BX
add AX, 2
$(inline_r("rcl", "BX", "AX"))
sub AX, 2
jz BX, %PS
dec BX
jz BX, %PK
out .(
^mov BX, AX
$(inline_r("rcl", "AX", "BX"))
#call("P")
inc BX
$(inline_r("rcl", "AX", "BX"))
#call("P")
out .)
pop BX
ret
@PS
out .S
pop BX
ret
@PK
out .K
pop BX
ret
@A
mov HX, *heap
#call("rcl_i")
add GX, 2
^mov HX, AX
#call("sto_i")
inc GX
ots GX, *heap
sub GX, 3
^mov AX, GX
ret
@read
^push BX
in BX
clr AX
ceq BX, .S
cjnz %RK
ceq BX, .K
cadd AX, 1
cjnz %RK
add AX, 2
#call("A")
mov BX, AX
#call("read")
$(inline("sto", "BX", "AX"))
#call("read")
inc BX
$(inline("sto", "BX", "AX"))
dec BX
^mov AX, BX
in BX
pop BX
ret
@RK
#call("A")
pop BX
ret
@eval
^push CX
$(inline_r("rcl", "BX", "AX"))
jz BX, %skip
$(inline_r("rcl", "CX", "BX"))
jz CX, %skip
add CX, 2
$(inline_r("rcl", "DX", "CX"))
cne DX, 1
cjnz %skip
inc BX
$(inline_r("rcl", "CX", "BX"))
mov AX, CX
mov GX, *changed
mov HX, 1
#call("sto_i")
jmp %not_bi
@skip
$(inline_r("rcl", "BX", "AX"))
jz BX, %notS
$(inline_r("rcl", "CX", "BX"))
jz CX, %notS
$(inline_r("rcl", "DX", "CX"))
jz DX, %notS
add DX, 2
$(inline_r("rcl", "BX", "DX"))
jnz BX, %notS
inc AX
$(inline_r("rcl", "FX", "AX"))
dec AX
$(inline_r("rcl", "BX", "AX"))
$(inline_r("rcl", "CX", "BX"))
inc BX
inc CX
$(inline_r("rcl", "EX", "BX"))
$(inline_r("rcl", "DX", "CX"))
mov AX, 2
#call("A")
^mov BX, AX
mov AX, 2
#call("A")
$(inline("sto", "BX", "AX"))
$(inline("sto", "AX", "DX"))
inc AX
$(inline("sto", "AX", "FX"))
mov AX, 2
#call("A")
inc BX
$(inline("sto", "BX", "AX"))
dec BX
$(inline("sto", "AX", "EX"))
inc AX
$(inline("sto", "AX", "FX"))
mov AX, BX
mov GX, *changed
mov HX, 1
#call("sto_i")
jmp %not_bi
@notS
$(inline_r("rcl", "BX", "AX"))
cge BX, 2
cjz %not_bi
^mov CX, AX
$(inline_r("rcl", "AX", "CX"))
#call("eval")
$(inline("sto", "CX", "AX"))
inc CX
$(inline_r("rcl", "AX", "CX"))
#call("eval")
$(inline("sto", "CX", "AX"))
dec CX
^mov AX, CX
@not_bi
pop CX
ret
#def_inline("sto")
#def_inline("rcl")