-
Notifications
You must be signed in to change notification settings - Fork 2
/
char.asm
110 lines (101 loc) · 995 Bytes
/
char.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
_str_len:
mov SI, A
mov A, 0
@@:
cmp byte [SI], 0
jz @f
inc SI
inc A
jmp @b
@@:
ret
_prn_str:
mov C, A
mov A, B
@@:
mov B, [A]
push C
push A
cinvoke putchar, B
pop A
inc A
pop C
loop @b
ret
macro chars str, [s] {
common
jmp @f
local .x
.x db str
forward
if ~ s eq
db s
end if
common
db 0
@@:
mov A, .x
}
macro puts str, [s] {
common
pushall
jmp @f
local .x
.x db str
forward
if ~ s eq
db s
end if
common
db 0
@@:
mov A, .x
call _str_len
mov B, .x
call _prn_str
popall
}
_prn_int:
pushall
mov BP, SP
sub SP, 10
@@:
mov B, 10
mov D, 0h ; high dword
div B
push A
mov B, D
add B, 48
dec BP
mov byte [BP], bl
pop A
cmp A, 0
jnz @b
mov A, BP
sub A, SP
mov B, 10
sub B, A
mov A, B
mov B, BP
call _prn_str
add SP, 10
puts ' '
popall
ret
macro str_cmp a, alen, b, blen {
get alen, B
get blen, C
mov A, 1
cmp C, B
jne @f
get alen, C
pair a, b
mov SI, B
mov DI, A
cld
mov A, 0
repe cmpsb
je @f
mov A, 1
@@:
}