-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path37.asm
207 lines (166 loc) · 2.29 KB
/
37.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
[org 0x0100]
push _str
push substr2
call findSubstr
mov ax, 0x4c00
int 21h
findSubstr:
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
push di
push es
sub sp, 2
push word [bp+4]
call strlen
pop dx
sub sp, 2
push word [bp+6]
call strlen
pop cx
sub cx, dx
add cx, 1
cmp cx, 0
jl not_found
mov bx, [bp+4]
mov al, [bx]
mov bx, ds
mov es, bx
mov di, [bp+6]
_main:
repne scasb
cmp cx, 0
je not_found
push 0
push di
push word [bp+4]
call confirm_found
pop dx
cmp dx, 1
je found
inc di
dec cx
jmp _main
found:
push msg1
jmp _end
not_found:
push msg2
_end:
call print
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 4 ;clear parameters
strlen:
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
push di
push es
mov cx, 0xffff
mov ax, 0
mov bx, ds
mov es, bx
mov di, [bp+4]
repne scasb
mov ax, 0xffff
sub ax, cx
mov [bp+6], ax
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 2 ;clear parameters
confirm_found:
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
push di
push es
sub sp, 2
push word [bp+4]
call strlen
pop cx
dec cx
mov si, [bp+6]
mov bx, ds
mov es, bx
mov di, [bp+4]
inc di
repe cmpsb
cmp cx, 0
jne __end
mov word [bp+8], 1
__end:
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 4 ;clear parameters
print:
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
push di
push es
mov bx, 0xb800
mov es, bx
mov di, 0
sub sp, 2
push word [bp+4]
call strlen
pop cx
dec cx
cld
mov si, 0
mov ah, 0x07
mov bx, [bp+4]
main_print:
mov al, [bx+si]
stosw
inc si
loop main_print
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 2 ;clear parameters
_str: db 'Marry has a little lamb.',0
substr1: db 'lamb',0 ; findSubstr prints “Substring Found.” for this substring.
substr2: db 'lame',0 ; findSubstr prints “Substring Not Found.” for this substring.
msg1: db 'Substring Found.',0
msg2: db 'Substring Not Found.',0