-
Notifications
You must be signed in to change notification settings - Fork 2
/
macro.asm
83 lines (71 loc) · 1.18 KB
/
macro.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
macro log str { puts str, 10 }
macro pushall { irp R, BP, D, C, B, A, SI, DI \{ push R \} }
macro popall { irp R, DI, SI, A, B, C, D, BP \{ pop R \} }
macro draw [arg] {
forward
get arg
call _str_len
push A
get arg, B
pop A
call _prn_str
puts ' '
}
macro show [arg] {
forward
get arg
call _prn_int
}
macro change name, value {
get name
add A, value
set name
}
macro check name, value, jumpto {
get name
cmp A, value
jne jumpto
}
macro cycle name, value, jumpto {
change name, 1
pair name, value
cmp A, B
jne .loop_#jumpto
}
macro lab l { .loop_#l: }
macro alloc numbers { cinvoke malloc, numbers * INTSIZE }
_gcount equ 0
macro gvar [name] {
forward
name equ _gcount
_gcount equ _gcount + INTSIZE
}
macro global x { mov A, [memory + x] }
macro gset id, [value] {
if ~ value eq
mov [memory + id], INTTYPE value
else
mov [memory + id], A
end if
}
macro ref name, index {
get name
if index eq
mov A, [A]
else
mov A, [A - INTSIZE * index]
end if
}
macro setref name, index_or_value, value {
if value eq
mov C, INTTYPE index_or_value
else
mov C, INTTYPE value
end if
get name
if value eq
mov [A], C
else
mov [A - INTSIZE * index_or_value], C
end if
}