forked from DarthJDG/NumGuess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numguess.asm
311 lines (249 loc) · 4.46 KB
/
numguess.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
308
309
310
311
.MODEL SMALL
.CODE
start:
mov ax,3h
int 10h
mov dx,OFFSET WelcomeMessage
mov ax,SEG WelcomeMessage
mov ds,ax
mov ah,9
int 21h
mov dx,OFFSET EnterName
mov ax,SEG EnterName
mov ds,ax
mov ah,9
int 21h
;get player name
mov dx,OFFSET PlayerName
mov ax,SEG PlayerName
mov ds,ax
mov ah,3fh
mov bx,0
mov cx,1eh
int 21h
mov bp,ax
;welcome
mov dx,OFFSET Welcome
mov ax,SEG Welcome
mov ds,ax
mov ah,9
int 21h
;$ to the end!
mov di,OFFSET PlayerName
mov ax,SEG PlayerName
mov es,ax
mov es:[di+bp-2],0124h
mov dx,OFFSET PlayerName
mov ds,ax
mov ah,9
int 21h
mov dx,OFFSET Exclamation
mov ax,SEG Exclamation
mov ds,ax
mov ah,9
int 21h
;LetsGuess
mov dx,OFFSET LetsGuess
mov ax,SEG LetsGuess
mov ds,ax
mov ah,9
int 21h
startgame:
mov ah,2ch
int 21h
xor ax,ax
mov al,dl
inc ax
mov num,ax
cmp ax,64h
jae startgame
mov guesses,0
readguess:
mov ax,guesses
inc ax
mov guesses,ax
mov dx,OFFSET GuessPrompt
mov ax,SEG GuessPrompt
mov ds,ax
mov ah,9
int 21h
;get guess
mov dx,OFFSET Guess
mov ax,SEG Guess
mov ds,ax
mov ah,3fh
mov bx,0
mov cx,1eh
int 21h
mov dx,ax
mov bp,dx
;$ to the end!
mov di,OFFSET Guess
mov ax,SEG Guess
mov es,ax
mov es:[di+bp-2],0124h
xor cx,cx
checkifnum:
mov di,OFFSET Guess
mov ax,SEG Guess
mov es,ax
mov bp,cx
mov al,es:[di+bp]
cmp al,24h
je itisanumber
cmp al,30h
jb itisnotanumber
cmp al,39h
ja itisnotanumber
inc cx
jmp checkifnum
itisnotanumber:
mov dx,OFFSET NotANumber
mov ax,SEG NotANumber
mov ds,ax
mov ah,9
int 21h
jmp readguess
itisanumber:
xor cx,cx
xor ax,ax
processnum:
mov di,OFFSET Guess
mov dx,SEG Guess
mov es,dx
mov bp,cx
mov bl,es:[di+bp]
cmp bl,24h
je numprocessed
mul ten
cmp bl,30h
je num0
cmp bl,31h
je num1
cmp bl,32h
je num2
cmp bl,33h
je num3
cmp bl,34h
je num4
cmp bl,35h
je num5
cmp bl,36h
je num6
cmp bl,37h
je num7
cmp bl,38h
je num8
cmp bl,39h
je num9
jmp exit
num9:
inc ax
num8:
inc ax
num7:
inc ax
num6:
inc ax
num5:
inc ax
num4:
inc ax
num3:
inc ax
num2:
inc ax
num1:
inc ax
num0:
inc cx
jmp processnum
numprocessed:
mov gnum,ax
cmp ax,64h
ja rangeerror
cmp ax,num
ja damntoohigh
jb damntoolow
je hurray
damntoohigh:
mov dx,OFFSET TooHigh
mov ax,SEG TooHigh
mov ds,ax
mov ah,9
int 21h
jmp readguess
damntoolow:
mov dx,OFFSET TooLow
mov ax,SEG TooLow
mov ds,ax
mov ah,9
int 21h
jmp readguess
rangeerror:
mov dx,OFFSET OutOfRange
mov ax,SEG OutOfRange
mov ds,ax
mov ah,9
int 21h
jmp readguess
hurray:
mov dx,OFFSET Victory
mov ax,SEG Victory
mov ds,ax
mov ah,9
int 21h
cmp guesses,10
jna wanttoplay
mov dx,OFFSET OverTen
mov ax,SEG OverTen
mov ds,ax
mov ah,9
int 21h
wanttoplay:
mov dx,OFFSET PlayAgain
mov ax,SEG PlayAgain
mov ds,ax
mov ah,9h
int 21h
mov ah,00h
int 16h
mov bl,al
mov ax,3h
int 10h
cmp bl,"y"
je pagain
cmp bl,"Y"
je pagain
exit:
mov dx,OFFSET ThankYou
mov ax,SEG ThankYou
mov ds,ax
mov ah,9h
int 21h
mov ax,4c00h
int 21h
pagain:
jmp StartGame
.DATA
WelcomeMessage db "Welcome to NumGuess for ASM!$"
EnterName db 0dh,0ah,0dh,0ah,"Enter your name (max 15 chars): $"
Welcome db "Welcome $"
Exclamation db "!",0dh,0ah,0dh,0ah,"$"
LetsGuess db "Let's see how good you are!",0dh,0ah,"Guess my number between 1 and 100!",0dh,0ah,0dh,0ah,"$"
GuessPrompt db "Guess: $"
TooHigh db "Too high!",0dh,0ah,0dh,0ah,"$"
TooLow db "Too low!",0dh,0ah,0dh,0ah,"$"
NotANumber db "This is not a number!",0dh,0ah,0dh,0ah,"$"
OutOfRange db "Out of range!",0dh,0ah,0dh,0ah,"$"
Victory db "You won! How did you do that?",0dh,0ah,0dh,0ah,"$"
OverTen db "Over ten guesses? Lame!",0dh,0ah,0dh,0ah,"$"
PlayAgain db 0dh,0ah,"Play again (Y/N)?$"
ThankYou db "Thank you for playing NumGuess ASM version!",0dh,0ah,"Copyright(C) 2000, DarthJDG",0dh,0ah,"$"
guesses dw 0
num dw 0
gnum dw 0
ten dw 10
PlayerName db " "
Guess db " "
END