this is the bingo game part that I have! the only missing thing here is that I couldn’t figure out how to check and print if the player wins (bingo) or he lost (no Bingo!!)! the part in which I need help is to combine the bingo part with a dice game that generates random numbers that I can use to mark different positions in a bingo chart.# ————————————————–
# Description: This is a bingo game.
# ————————————————–
# Your annotated registers
# ————————————————–
.data
greeting: .asciiz “Welcome to bingo.nnn”
bingotable: .ascii “n======B I N G O =========”
.ascii “n 5 17 32 43 62 “
.ascii “n 7 19 34 45 63 “
.ascii “n 9 21 36 47 64 “
.ascii “n 11 23 38 49 65 “
.ascii “n 13 25 40 50 67 “
.ascii “n==========================================”
board: .byte ‘ ‘, ‘ ‘, ‘B’, ‘ ‘, ‘I’, ‘ ‘, ‘N’, ‘ ‘, ‘G’, ‘ ‘, ‘O’, ‘n’
.byte ‘1’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘n’
.byte ‘2’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘n’
.byte ‘3’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘n’
.byte ‘4’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘n’
.byte ‘5’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘ ‘, ‘_’, ‘n’
userchoice: .asciiz “nEnter your choice (Q to quit): “
marked: .asciiz “nPosition marked.nn”
invalid: .asciiz “nInvalid position.nn”
markposition: .asciiz “nPosition already marked.nn”
win: .asciiz “n !! BINGO !! n”
lose: .asciiz “n No Bingo “
.text
.globl main
main:
la $a0, greeting
li $v0, 4
syscall
#display a bingo table
la $a0, bingotable
li $v0, 4
syscall
#jump and link function boardchart
jal boardchart
sw $t0, -4($sp)
sw $t1, -8($sp)
sw $t2, -12($sp) #temp to stack
jal input
lw $t0, 4($sp)
lw $t1, 8($sp)
lw $t2, 12($sp) #temp from stack
move $t0, $a0 # input letter to $t0 (col)
move $t1, $a1 # input number to $t1 (row)
looptop:
li $t2, 81 # Q load immediate
beq $t0, $t2,loopexit #looptop
loopbody:
move $a0, $t0
move $a1, $t1
la $a2, board
sw $t0, -4($sp)
sw $t1, -8($sp)
sw $t2, -12($sp) #store all temp to stack
jal myPosition
lw $t0, 4($sp)
lw $t1, 8($sp)
lw $t2, 12($sp) #load all temp from stack
jal boardchart
#t
sw $t0, -4($sp)
sw $t1, -8($sp)
sw $t2, -12($sp) #temp to stack
jal input
lw $t0, 4($sp)
lw $t1, 8($sp)
lw $t2, 12($sp) #temp from stack
move $t0, $a0
move $t1, $a1
j looptop
loopexit:
li $t4, 0 #count (NULL)
li $t8, 0 #count 2 (NULL)
li $t9, 55 #count 3
li $t5, 4 #loop end if end of transmission
li $t6, 70 #other loop end if F
la $a2, board
move $t2, $a2 #$t2 = board
li $t0, ‘X’ #$t0 = X
addi $t3, $t2, 14 #$t3 = board + 14 (0,0)
lb $t1, 0($t3) #$t1 = what’s in $t2
beq $t1, $t0, rowCol
looping:
addi $t3, $t3, 12 #add 12 to board (move down)
lb $t1, 0($t3) #load byte
beq $t1, $t0, rowCol
sub $t7, $t3, $t2
bgt $t7, $t6, looping2 #this should branch when $t3 > 62
j looping
looping2:
addi $t3, $t2, 14
looping3:
addi $t3, $t3, 2 #add 2 to board (move right)
lb $t1, 0($t3)
beq $t1, $t0, check2
sub $t7, $t3, $t2
bgt $t7, $t6, noluck
addi $t9, $9, 1
j looping3
rowCol:
addi $t4, $t4, 1
addi $t3, $t3, 2 #add 2 to the location of board (move over)
lb $t1, 0($t3)
bne $t1, $t0, check
beq $t4, $t5, bingo
j rowCol
check:
sub $t3, $t3, 2 #subtract the 2 from rowCol
check2:
li $t9, 55 #reset count3
addi $t4, $t4, 1 #count
addi $t3, $t3, 12 #add 12 to location (move down)
lb $t1, 0($t3)
bne $t1, $t0, check3 #where to branch to?
bne $t4, $t5, bingo #beq ????????????????????????????????????????
j check2
check3:
li $t4, 1 #start of heading
addi $t8, $t8, 1
beq $t8, $t5, looping3
j looping
bingo:
la $a0, win
li $v0, 4
syscall
j EXIT
noluck:
la $a0, lose
li $v0, 4
syscall
j EXIT
boardchart:
la $a0, board
li $v0, 4
syscall #display board
jr $ra
la $a0, userchoice #display input message
li $v0, 4
syscall
input:
li $v0, 12
syscall # read letter (ascii)
move $a0, $v0
li $v0, 5
syscall # read usernumber
move $a1, $v0
li $t0, 66 # B numbers in dec
li $t1, 73 # I
li $t2, 78 # N
li $t3, 71 # G
li $t4, 79 # O
beq $a0, $t0, equalB
beq $a0, $t1, equalI
beq $a0, $t2, equalN
beq $a0, $t3, equalG
beq $a0, $t4, equalO
j endIf
equalB:
la $a0, 0
j endIf
equalI:
la $a0, 1
j endIf
equalN:
la $a0, 2
j endIf
equalG:
la $a0, 3
j endIf
equalO:
la $a0, 4
endIf:
sub $a1, $a1, 1
jr $ra
myPosition:
#void myPosition (int col, int row)
# {
#update the board array
#set status to 0 if mark successful
#set stattus to 1 if position already marked
#set stattus to 2 if invalid position
#display status
#display status(status)
#}
addi $sp, $sp, -4
sw $ra, 0($sp)
move $t0, $a0
#row
move $t1, $a1 #row
move $t2, $a2 #array
li $t9, ‘X’ #X for marking laod immeadiate before ‘X’
li $t3, 14 #numCol
li $t4, 2 #constant for formula
li $t5, 1 #constant for formula
add $t1, $t1, $t5 #$t1 = row + 1
mult $t3, $t1
mflo $t6 #$t6 = 14(row + 1)
mult $t1, $t4
mflo $t8 #$t8 = (row * 2)
sub $t1, $t6, $t8 #$t1 = 14(row + 1) – (row * 2)
mult $t0, $t4
mflo $t7 #$t7 = col*2
add $t1, $t1, $t7 #$t1 = (14(row + 1) – (row *2)+(col*2)
addi $t1, $t1, 2 #$t1 + 2
add $t2, $t2, $t1 #moves $t2 to correct position
lb $t4 0($t2) #loads what’s in the position to $t4
beq $t4, $t9, ifAlready #if $t2 == X
li $t5, 2
div $t1, $t5 #$t1 / 2
mfhi $t6 #remainder
bne $t6, 0, ifInvalid #$t1 % 2 != 0
blt $t1, 14, ifInvalid #if $t1 < 14
bgt $t1, 70, ifInvalid #if $t1 > 70
beq $t1, 24, ifInvalid #if $t1 = 24
beq $t1, 36, ifInvalid #if $t1 = 36
beq $t1, 48, ifInvalid #if $t1 = 48
beq $t1, 60, ifInvalid #if $t1 = 60
ifSuccess:
li $t7, 0 #status = 0
sb $t9, 0($t2)
j ifEnd
ifAlready:
li $t7, 1 #status = 1
j ifEnd
ifInvalid:
li $t7, 2 #status = 2
ifEnd:
move $a0, $t7
jal displayStatus
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
displayStatus:
addi $sp, $sp, -4
sw $ra, 0($sp)
bne $a0, 0, ifSucess
beq $a0, 1, ifAlredy
beq $a0, 2, iffails
ifSucess:
la $a0, marked #position marked
li $v0, 4
syscall
j ifExit
ifAlredy:
la $a0, markposition
li $v0, 4
syscall
j ifExit
iffails:
la $a0, invalid
li $v0, 4
syscall
ifExit:
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
EXIT:
li $v0, 10
syscall


0 comments