-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhangman.asm
159 lines (110 loc) · 2.73 KB
/
hangman.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
; Roberto Luiz Debarba <roberto.debarba@gmail.com> 2015
; 8086 Assembly, emu8086
data segment
welcome_message db "HANGMAN (Jogo da Forca) by Roberto Luiz Debarba!$"
type_message db "Type a letter: $"
new_line db 13, 10, "$"
win_message db "YOU WIN!$"
lose_message db "YOU LOSE!$"
word db "roberto$"
discovered_word db 7 dup("-"), "$"
word_size db 7
lives db 5
hits db 0
errors db 0
ends
stack segment
dw 128 dup(?)
ends
extra segment
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov ax, extra
mov es, ax
; add your code here
main_loop:
lea dx, welcome_message
call print
lea dx, new_line
call print
call print
lea dx, discovered_word
call print
lea dx, new_line
call print
call print
call check
lea dx, type_message
call print
call read_keyboard
call update
call clear_screen
loop main_loop
check:
mov bl, ds:[lives]
mov bh, ds:[errors]
cmp bl, bh
je game_over
mov bl, ds:[word_size]
mov bh, ds:[hits]
cmp bl, bh
je game_win
ret
update:
lea si, word
lea di, discovered_word
mov bx, 0
update_loop:
cmp ds:[si], "$"
je end_word
; check if letter is already taken
cmp ds:[di], al
je increment
; check if letter is on the word
cmp ds:[si], al
je equals
increment:
inc si
inc di
jmp update_loop
equals:
mov ds:[di], al
inc hits
mov bx, 1
jmp increment
end_word:
cmp bx, 1
je end_update
inc errors
end_update:
ret
game_over:
lea dx, lose_message
call print
jmp fim
game_win:
lea dx, win_message
call print
jmp fim
clear_screen: ; get and set video mode
mov ah, 0fh
int 10h
mov ah, 0
int 10h
ret
read_keyboard: ; read keyborad and return in al
mov ah, 1
int 21h
ret
print:
mov ah, 9
int 21h
ret
FIM:
jmp fim
code ends
end start