-
Notifications
You must be signed in to change notification settings - Fork 2
/
lang.asm
164 lines (144 loc) · 1.93 KB
/
lang.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
LOCAL_MEM = 10
FUNC_NAME equ 'undefined '
COUNT_MAX = 0
macro func name, x {
FUNC_NAME equ `name
COUNT_MAX = LOCAL_MEM
name:
if x eq
mov A, LOCAL_MEM * INTSIZE
else
mov A, x * INTSIZE
COUNT_MAX = x
end if
push BP
mov BP, SP
sub SP, A
push A
_count equ 0
}
macro var [_arg] {
forward
_arg equ _count
_count equ _count + 1
}
macro use [_arg] {
forward
_arg equ _count
_count equ _count + 1
arg _arg
set _arg
}
macro display_num n {
display '0'+ n/100, '0'+ (n - (n/100)*100) / 10, '0'+ n - (n/10)*10
display ' '
}
macro exi n {
if _count > COUNT_MAX
display 10,' Error: in function "'
display FUNC_NAME, '" '
display_num (_count)
display 'arguments defined, but only '
display_num (COUNT_MAX)
display 'reserved ', 10,10
success = 1
end if
pop B
add SP, B
pop BP
if ~ n eq
mov A, n
end if
ret
}
macro popvoid x { add SP, INTSIZE }
macro exe f, [a] {
if a eq
push A
call f
popvoid
else
reverse
;mov A, a
;push A
push INTTYPE a
common
call f
reverse
popvoid a
end if
}
macro pass f, [a] {
reverse
get a
push A
common
call f
reverse
popvoid a
}
;macro unpush z { pop B }
macro arg a, b {
if b eq
mov B, a
imul B, INTSIZE
mov A, [BP + B + INTSIZE * 2]
else
mov B, b
imul B, INTSIZE
mov a, [BP + B + INTSIZE * 2]
end if
}
macro get n, dest { ; we lose only A
push B
mov B, n
inc B
imul B, INTSIZE
mov A, BP
sub A, B
pop B
if dest eq
mov A, [A]
else
mov dest, [A]
end if
}
macro pet n, dest {
mov B, n
inc B
imul B, INTSIZE
mov A, BP
sub A, B
if ~ dest eq
mov dest, A
end if
}
macro set n, v {
mov C, n
inc C
imul C, INTSIZE
mov B, BP
sub B, C
if ~ v eq
mov [B], INTTYPE v
else
mov [B], A
end if
}
macro pair a, b { ; a->ax, b->bx
get a
push A
get b
mov B, A
pop A
}
macro copy dest, src {
get src
set dest
}
; op A, A, inc, B
macro op dest, src1, operation, src2 {
pair src1, src2
operation A, B
set dest
}