-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
579 lines (449 loc) · 11.6 KB
/
main.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
.include "function.asm"
.include "record.asm"
.include "graphics.asm"
.include "choose_word.asm"
.text
main:
# oyunun sizi karsilayacagi kisim
la $a0, helloGame
messagebox($a0, 1)
# oyuncunun ismini giris yaptigi kisim
InputPlayerName:
la $a0, askPlayerName
la $a1, playerName
#ismi a1 de sakl�yorum
inputmessagebox($a0, $a1, 20)
num($a1)
beq $v0, 0, InputPlayerName
# kelimelerimi sayiyorum yaklasik 25 kelimem bulunmakta
li $s0, 0
la $a0, tempStr
Dictionary:
getline($s0, $a0, ',', wordbox)
beq $v0, -1, EndDictionary
addi $s0, $s0, 1
j Dictionary
EndDictionary:
sw $s0, numWordDictionary
Hangman:
# bosaltiyoruz ekrani
li $a0, 0
li $a1, 0
LoopYClearScreen:
LoopXClearScreen:
drawPixel($a0, $a1, 0x00000000)
addi $a0, $a0, 1
blt $a0, 128, LoopXClearScreen
li $a0, 0
addi $a1, $a1, 1
blt $a1, 128, LoopYClearScreen
# gizli kelimeyi aliyoruz
la $a0, hiddenWord
lw $a1, numWordDictionary
choose($a1)
move $s0, $v0
getline($s0, $a0, ',', wordbox)
# tahminde bulunuyoruz
length($a0)
move $t0, $v0
la $a0, guessWord
string($a0, 'x', $t0)
LoopGuessOneWord:
# gösteriyoruz
la $a0, guessWord
messagebox($a0, 1)
# secim yapiyoruz
la $a0, chooseGuessWord
confirmbox($a0)
move $a0, $v0
#secimine gore yol izliyoruz char(harf) yada word tahmin etmek icin
beq $a0, 0, InputGuessOneWord
beq $a0, 1, InputGuessOneChar
j InputGuessOneChar
InputGuessOneWord:
la $a0, askInputWord
la $a1, guessWord
inputmessagebox($a0, $a1, 10)
# kontol ediyoruz do�ru mu degil mi (kelime icin)
j _CheckGuessWord
InputGuessOneChar:
la $a0, askInputChar
la $a1, tempStr
inputmessagebox($a0, $a1, 5)
lb $a0, 0($a1)
sb $a0, guessChar
# kontol ediyoruz do�ru mu degil mi (harf icin)
#harf kelimemin i�inde geciyorsa yazarak belirtilir
j _CheckGuessChar
# kelime icin kontol yapt�gimiz kisim
_CheckGuessWord:
la $a0, hiddenWord # gercek kelimem
la $a1, guessWord #kullanicinin tahmini
#oncelikle 2 deger dusunuyorum ki esit olup olmadigini degerlendirebileyim
# karsilastir ( gizli kelime ve tahmin edilen kelime )
compare($a0, $a1)
beq $v0, 1, GuessWordRight
j GuessWordWrong
#kelimeyi tekde dogru tahmin ettigimizde
GuessWordRight:
# noti right word
la $a0, notiRightWord
messagebox($a0, 1)
# sifirliyoruz
sb $zero, playerStatus
# score
lw $a0, playerScore
la $a1, hiddenWord
length($a1)
add $a0, $a0, $v0
sw $a0, playerScore
# sayisi : right word
lw $a0, playerWord
addi $a0, $a0, 1
sb $a0, playerWord
# oyuna devam edip kullanicinin tekrar oynamasini sagliyoruz
j Hangman
#yanlis kelimeyi takip ettigimizde adamimiz malesef ki direkt olarak asiliyor
GuessWordWrong:
# oyuncuyu kaydediyoruz
la $a0, playerName
saveString($a0, 1, dataPlayer)
saveChar('-', 1, dataPlayer)
lw $a0, playerScore
la $a1, tempStr
toString($a1, $a0)
saveString($a1, 1, dataPlayer)
saveChar('-', 1, dataPlayer)
lw $a0, playerWord
toString($a1, $a0)
saveString($a1, 1, dataPlayer)
saveChar('*', 1, dataPlayer)
# status player = 7
li $a0, 7
sb $a0, playerStatus
# ekranda gosteriyoruz
j _Lose
#kullanicinin tahmin ettigi harf bizim kelimemizin icinde var mi yok mi diye kontol ettigimiz kisim
_CheckGuessChar:
# tam karakterin dolu olup olmad���n� kontrol ediyoruz gizli kelimeyle karsilastiriyoruz
la $a0, hiddenWord
la $a1, guessWord
find($a1, 0, 'x') #harf al�yorum kullanicidan guide gordugunuz her x bir harfi temsil etmekte
beq $v0, -1, _CheckGuessWord
# Tahmini karakter iceren gizli kelimeyi kontrol etigimiz kisim
lb $a0, guessChar
la $a1, hiddenWord
find($a1, 0, $a0)
beq $v0, -1, Nothidden
j hidden
Nothidden:
lb $a0, playerStatus
addi $a0, $a0, 1
sb $a0, playerStatus
beq $a0, 7, GuessWordWrong
# yanlis cevabi goster
la $a0, notiWrongChar
messagebox($a0, 0)
# burada yaptigim yanlislar adami asmamda etkili olacak
jal _DrawPlayerStatus
# jump to Loop Guess One word kelime tahminine geri d�n�yrum
j LoopGuessOneWord
hidden:
# total degerlerim tahmin edilebilir olan kelimem ve harfim dogru ve sakli olan bir kelimem bunlar uzerinden ilerleyecegiz
la $a0, guessWord
lb $a1, guessChar
la $a2, hiddenWord
li $t0, -1
LoopFillChar:
# prevPos + 1 = posStartFind
addi $t0, $t0, 1
# gizli kelimede pos char buluyoruz
find($a2, $t0, $a1)
move $t0, $v0
# tahmin edileni kaydediyoruz
add $a0, $a0, $t0
sb $a1, ($a0)
sub $a0, $a0, $t0
bne $t0, -1, LoopFillChar
compare($a0, $a2)
beq $v0, 1, GuessWordRight
# kelime tahminine geri deniyorum
j LoopGuessOneWord
# burada kullanicinin yanlis tahminlerine gore adami cizdirecegiz
_Lose:
# adami cizdiriyorum
jal _DrawPlayerStatus
la $a0, notiLostGame
messagebox($a0, 0)
# oyuncuya skorunu gosteriyoruz
la $a0, notiInfor
printString($a0)
la $a0, notiName #ismi a0 atiyoruz
la $a1, notiScore #kazandigi scor a1 atiyoruz
la $a2, notiWord #bildigi kelimeler a2 atiyoruz
#yazdiriyoruz a0,a1,a2
printString($a0)
printString($a1)
printString($a2)
la $a0, playerName
lw $a1, playerScore
lw $a2, playerWord
printString($a0)
printChar('\t')
printInt($a1)
printChar('\t')
printInt($a2)
printChar('\n')
# reset
sb $zero, playerStatus
sw $zero, playerScore
sw $zero, playerWord
# burada kullanicimiza oyundan cikmak ister mi diye soruyoruz
la $a0, askStatusGame
confirmbox($a0)
#eger cikmak isterse bu oyunu oynayanlar arasindan ilk 10 un scorlarini,isimlerini,kac kelime bildiklerini gostermekteyiz
beq $v0, 0, Hangman
j _BestPlayer
_DrawPlayerStatus:
pushStack($ra)
pushStack($t0)
#adamimiz 7 parcadan olusuyor asilacak bolumleri
lb $t0, playerStatus
#statusuma gore asma islemini baslatiyorum
beq $t0, 1, draw1
beq $t0, 2, draw2
beq $t0, 3, draw3
beq $t0, 4, draw4
beq $t0, 5, draw5
beq $t0, 6, draw6
beq $t0, 7, draw7
j EndDraw
draw7: gallowsdesign(7)
draw6: gallowsdesign(6)
draw5: gallowsdesign(5)
draw4: gallowsdesign(4)
draw3: gallowsdesign(3)
draw2: gallowsdesign(2)
draw1: gallowsdesign(1)
EndDraw:
popStack($t0)
popStack($ra)
jr $ra
_BestPlayer:
# oyuncularini numaralandir
li $s0, 0
la $a0, tempStr
LoopCountPlayer:
# oyunculari ayirdigim kisim * ile ayirmaktayim
getline($s0, $a0, '*', dataPlayer)
beq $v0, -1, EndLoopCountPlayer
addi $s0, $s0, 1
j LoopCountPlayer
EndLoopCountPlayer:
sw $s0, numPlayer
# dynamic allocation
li $gp, 0x10040000 # heap
lw $s0, numPlayer
# oyuncu ismi
mul $t0, $s0, 24 # her isim len = 20 bir tane bo�
sw $gp, allPlayerNameBuffPtr
add $gp, $gp, $t0
# score
mul $t0, $s0, 4 # 1 score = 1 word = 4 bytes
sw $gp, allPlayerScorePtr
add $gp, $gp, $t0
# ptr name
sw $gp, allPlayerNamePtr
add $gp, $gp, $t0
# number word
sw $gp, allPlayerWordPtr
add $gp, $gp, $t0
# datalarimi yukluyorum
li $s1, 0
la $a0, tempStr
lw $a1, allPlayerNamePtr
lw $a2, allPlayerScorePtr
lw $a3, allPlayerWordPtr
lw $s0, allPlayerNameBuffPtr
# dosyadan okuyorum cunku oyunculari dosyada tutuyordum scorlarini
LoopReadDataPlayer:
# her oyuncu * ile ayr�l�yor
getline($s1, $a0, '*', dataPlayer)
beq $v0, -1, EndLoopReadDataPlayer
# ismini aliyorum oyuncunun
getstr($s0, $a0, '-', 0)
sw $s0, ($a1)
addi $s0, $s0, 24
addi $a1, $a1, 4
# scorunu aliyorum
getstr($a2, $a0, '-', 1)
int($a2)
sw $v0, ($a2)
lw $s3, ($a2)
addi $a2, $a2, 4
# kac kelime bildigini aliyorum
getstr($a3, $a0, '-', 2)
int($a3)
sw $v0, ($a3)
addi $a3, $a3, 4
addi $s1, $s1, 1
# bunu tekrarl�yorum
j LoopReadDataPlayer
EndLoopReadDataPlayer:
# burada oyuncular aras� siralama yapacagim kisim
lw $a0, allPlayerNamePtr
lw $a1, allPlayerScorePtr
lw $a2, allPlayerWordPtr
li $t0, 0 # i
li $t1, 0 # j
li $t2, 0 # max_index
lw $t3, numPlayer
li $t4, 0 # address arr[j]
li $t5, 0 # address arr[min_index]
li $t6, 4
li $s0, 0
li $s1, 0
li $s2, 0
LoopForI:
move $t2, $t0
bge $t0, $t3, EndLoopForI
move $t1, $t0
LoopForJ:
bge $t1, $t3, EndLoopForJ
# cal address arrayin elemanlarinin
mult $t1, $t6
mflo $t4
mult $t2, $t6
mflo $t5
# karsilastirma and degistirme (max_index)
add $a1, $a1, $t4
lw $s0, ($a1)
sub $a1, $a1, $t4
add $a1, $a1, $t5
lw $s1, ($a1)
sub $a1, $a1, $t5
bgt $s0, $s1, ChangeMaxIndex
j IncreaseJ
ChangeMaxIndex:
move $t2, $t1
IncreaseJ:
addi $t1, $t1, 1
beq $zero, $zero, LoopForJ
EndLoopForJ:
# desigtir
mul $t4, $t2, 4
mul $t5, $t0, 4
# isim degistirdigim kisim
add $a0, $a0, $t4
lw $s0, ($a0)
sub $a0, $a0, $t4
add $a0, $a0, $t5
lw $s1, ($a0)
sub $a0, $a0, $t5
swap($s0, $s1)
add $a0, $a0, $t4
sw $s0, ($a0)
sub $a0, $a0, $t4
add $a0, $a0, $t5
sw $s1, ($a0)
sub $a0, $a0, $t5
#scoru degistirdigim kisim
add $a1, $a1, $t4
lw $s0, ($a1)
sub $a1, $a1, $t4
add $a1, $a1, $t5
lw $s1, ($a1)
sub $a1, $a1, $t5
swap($s0, $s1)
add $a1, $a1, $t4
sw $s0, ($a1)
sub $a1, $a1, $t4
add $a1, $a1, $t5
sw $s1, ($a1)
sub $a1, $a1, $t5
# bildigi kelimelere gore degistigim kisim
add $a2, $a2, $t4
lw $s0, ($a2)
sub $a2, $a2, $t4
add $a2, $a2, $t5
lw $s1, ($a2)
sub $a2, $a2, $t5
swap($s0, $s1)
add $a2, $a2, $t4
sw $s0, ($a2)
sub $a2, $a2, $t4
add $a2, $a2, $t5
sw $s1, ($a2)
sub $a2, $a2, $t5
addi $t0, $t0, 1
beq $zero, $zero, LoopForI
EndLoopForI:
# print header
printConstString("\n BEST PLAYERS ! \n")
la $a0, notiName
la $a1, notiScore
la $a2, notiWord
printString($a0)
printString($a1)
printString($a2)
# print best players
li $t0, 0
lw $t1, numPlayer
lw $a0, allPlayerNamePtr
lw $a1, allPlayerScorePtr
lw $a2, allPlayerWordPtr
bgt $t1, 10, Assign10
j LoopPrintBest
Assign10:
li $t1, 10
LoopPrintBest:
# load data
lw $s0, ($a0)
lw $s1, ($a1)
lw $s2, ($a2)
# print data
printString($s0)
printChar('\t')
printInt($s1)
printChar('\t')
printInt($s2)
printChar('\n')
# addresi artiriyorum
addi $a0, $a0, 4
addi $a1, $a1, 4
addi $a2, $a2, 4
addi $t0, $t0, 1
blt $t0, $t1, LoopPrintBest
# reset
li $sp, 0x10040000
.data
#kullanicimiza burada sorular yonetiyoruz..Kullanici isterse harf alabilir ya da risk alarak kelimenin tamamnini tahmin edebilir ama unutmayin ki yanlis tahmin ederse adamimiz tamamen asilir !
helloGame: .asciiz "Welcome to the game Hangman"
askPlayerName: .asciiz "Pleace enter your name"
askInputChar: .asciiz "Pleace enter the letter"
askInputWord: .asciiz "What is the word??"
askStatusGame: .asciiz "Do you want to continue the game?"
chooseGuessWord: .asciiz "Do you want to enter words?"
notiLostGame: .asciiz "Is there a problem ? "
notiRightWord: .asciiz "That's right, you're so good!!"
notiWrongChar: .asciiz "Did you do wrong?"
wordbox: .asciiz "wordbox.txt"
dataPlayer: .asciiz "playerinfo.txt" # oyunumuzu oynayanlar�n bilgilerini burada saklayacagiz
notiInfor: .asciiz "Player's infor\n"
notiName: .asciiz "Player Name\t"
notiScore: .asciiz "Player Score\t"
notiWord: .asciiz "Number of word\n"
allPlayerNameBuffPtr: .word 0
allPlayerNamePtr: .word 0
allPlayerScorePtr: .word 0
allPlayerWordPtr: .word 0
numWordDictionary: .word 0
numPlayer: .word 0
hiddenWord: .space 12
guessWord: .space 12
guessChar: .space 4
tempStr: .space 48
playerName: .space 24
playerScore: .word 0
playerWord: .word 0
playerStatus: .word 0