Gen_byte is generating two random bits 00,01,10 (not 11) for a rock paper scissors game. 00 is rock, 01 is paper and 10 is scissors. This play_game function is checking if player 1 wins, looses or ties. The problem is that when I run the test the output goes like WLTWLTWLTWLT… and doesn’t stop. I’m not quite sure where the problem is.
vim:sw=2 syntax=asm
.data
result: .asciiz “WLT”
.text
.globl play_game_once
Play the game once, that is
(1) compute two moves (RPS) for the two computer players
(2) Print (W)in (L)oss or (T)ie, whether the first player wins, looses or ties.
Returns: Nothing, only print either character ‘W’, ‘L’, or ‘T’ to stdout
play_game_once:
jal gen_byte
move $s0, $v0
jal gen_byte
move $s1, $v0
#checking who wins
beq $s0, $s1, tie
beq $s0, 0, rock_win
beq $s0, 1, paper_win
beq $s0, 2, scissor_win
rock_win:
beq $s1, 2, player1_wins
j player2_wins
paper_win:
beq $s1, 0, player1_wins
j player2_wins
scissor_win:
beq $s1, 1, player1_wins
j player2_wins
player1_wins:
li $v0, 4
la $a0, result
li $a1, 1
li $a2, 0 #print W
syscall
j end_game
player2_wins:
li $v0, 4
la $a0, result
li $a1, 1
li $a2, 1 #print L
syscall
j end_game
tie:
li $v0, 4
la $a0, result
li $a1, 1
li $a2, 2 #print T
syscall
j end_game
end_game:
jr $ra
Tagore is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.