-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwordHunt.asm
307 lines (229 loc) · 5.64 KB
/
wordHunt.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
; Roberto Luiz Debarba <[email protected]> 2015
; 8086 Assembly, emu8086
data segment
; add your data here!
seed dw 2332h
rndnum dw 0
line db 0
column db 0
page_number db 0
word_1 db "ROBERTO$"
word_2 db "HOUSE$"
word_3 db "SCHOOL$"
word_4 db "COMPUTER$"
word_5 db "FRIEND$"
word_pointer dw dup 5 (?)
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
main_loop:
call set_word_pointer
call print_board
mov cx, 5
mov si, 0 ; index for word_pointer
mov di, 0 ; word direction
word_print_loop:
; column
mov dh, 30
mov al, 00011111b
call sort_number
; sort only 30 first columns and multuply by 2, the result is only even columns
mov al, dl
mov bl, 2
mul bl
mov dl, al
mov column, dl
; line
mov dh, 14
mov al, 00011111b
call sort_number
mov line, dl
; print
call print_word
xor di, 00000001b
add si, 2
loop word_print_loop
call end_check
call clear_screen
jmp main_loop
fim:
mov ax, 4c00h ; exit to operating system.
int 21h
sort_number: ; sort a number between 0 and DH; XOR with AL; store in dl
call random
mov dl, byte ptr rndnum
and dl, al
cmp dl, dh
jg sort_number
ret
print_word: ; print word stored in SI; DI:0 = vertical, DI:1 = horizontal
pushf
push ax
push dx
push si
push di
call set_cursor
mov si, word_pointer[si]
do_print_word:
mov ax, ds:[si]
cmp al, "$"
je end_print_word
call print_custon_character
inc si
cmp di, 0
je inc_line
cmp di, 1
je inc_column
return_check_position:
call set_cursor
; if is horizontal, print blanck space
cmp di, 1
je print_blanck_space
return_print_blanck_space:
jmp do_print_word
end_print_word:
pop di
pop si
pop dx
pop ax
popf
ret
inc_line:
inc line
jmp return_check_position
inc_column:
inc column
jmp return_check_position
print_blanck_space:
mov al, " "
call print_custon_character
inc column
call set_cursor
jmp return_print_blanck_space
end_check:
pushf
push ax
mov ah, 1
int 21h
cmp al, "E"
je fim
cmp al, "e"
je fim
pop ax
popf
ret
clear_screen: ; get and set video mode
pushf
push ax
mov ah, 0fh
int 10h
mov ah, 0
int 10h
pop ax
popf
ret
set_word_pointer:
mov word_pointer[0], offset word_1
mov word_pointer[2], offset word_2
mov word_pointer[4], offset word_3
mov word_pointer[6], offset word_4
mov word_pointer[8], offset word_5
ret
print_custon_character: ; print content stored in AL
pushf
push ax
push bx
push cx
mov ah, 09h
mov bh, page_number
mov bl, 10 ; color
mov cx, 1 ;number of times to print
int 10h
pop cx
pop bx
pop ax
popf
ret
print_board:
pushf
push cx
push dx
mov cx, 24 * 40
print_board_loop:
; get new letter
call random
mov dl, byte ptr rndnum
and dl, 00011111b
add dl, "A"
; check if is letter
cmp dl, "A"
jl print_board_loop
cmp dl, "Z"
jg print_board_loop
; print letter
call print_character
mov dl, " "
call print_character
loop print_board_loop
pop dx
pop cx
popf
ret
print_character: ; print character stored in DL
pushf
push ax
mov ah, 2
int 21h
pop ax
popf
ret
random:
pushf
push ax
push cx
push dx
mov ah, 2ch
int 21h
; segundos em dh
; usa tambem cx
mov ax, seed ; ax = seed
add al, dh
mov dx, 8405h ; dx = 8405h
mul dx ; mul (8405h * seed) into dword dx:ax
cmp ax, seed
jnz gotseed ; if new seed = old seed, alter seed
mov ah, dl
inc ax
gotseed:
mov seed, ax ; we have a new seed, so store it
mov ax, dx ; al = random number
mov rndnum, ax
pop dx
pop cx
pop ax
popf
ret
set_cursor:
pushf
push ax
push bx
push dx
mov ah, 2
mov bh, page_number
mov dh, line
mov dl, column
int 10h
pop dx
pop bx
pop ax
popf
ret
ends
end start