Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
mflo $t6
mfhi $t7
li $v0,10
mflo $t6
mfhi $t7
li $v0,10
welcome: .asciiz "Bienvenue dans le jeu de Mastermind.\nUne sequence de quatre chiffres de 1 à 8 a ete générée.\nA vous de la deviner !"
play: .asciiz "Commencer à jouer:"
welcome: .asciiz "Bienvenue dans le jeu de Mastermind.\nUne sequence de quatre chiffres de 1 à 8 a ete générée.\nA vous de la deviner !"
play: .asciiz "Commencer à jouer:"
-lost_msg: .asciiz "Vous avez perdu !"
+lost_msg: .asciiz "Vous avez perdu !"
win_msg: .asciiz "Vous avez gagné !"
win_msg: .asciiz "Vous avez gagné !"
-temp_msg: .asciiz " bien placé"
-exclamation_point: .asciiz "! "
+temp_msg: .asciiz " bien placé"
+exclamation_point: .asciiz "! "
interrogation_point: .asciiz "? "
newline: .asciiz "\n"
interrogation_point: .asciiz "? "
newline: .asciiz "\n"
la $a0, newline
li $v0, 4
syscall
la $a0, newline
li $v0, 4
syscall
generate_sequence:
la $t0, guess_value
generate_sequence:
la $t0, guess_value
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
li $a1, 8
li $v0, 42
syscall
addi $a0, $a0, 1 # Put the integer into the [1-8] range
generate_sequence_loop_end:
la $s0, ($zero) # Initialize loop counter to zero
generate_sequence_loop_end:
la $s0, ($zero) # Initialize loop counter to zero
la $a0, newline
li $v0, 4
syscall
la $a0, newline
li $v0, 4
syscall
la $a0, ($s0)
li $v0, 1
syscall
la $a0, interrogation_point
li $v0, 4
syscall
la $a0, ($s0)
li $v0, 1
syscall
la $a0, interrogation_point
li $v0, 4
syscall
la $a0, input_value # Store the answer
li $a1, 5
li $v0, 8 # Load syscall read_string
la $a0, input_value # Store the answer
li $a1, 5
li $v0, 8 # Load syscall read_string
- syscall # Make the syscall
+ syscall # Make the syscall
-# check that each input values are in the right range
+# check that each input values are in the right range
check_input:
la $t7, input_value
check_input:
la $t7, input_value
lb $t5, 0($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
bgez $t5, input
lb $t5, 0($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
bgez $t5, input
lb $t5, 1($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
bgez $t5, input
lb $t5, 1($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
bgez $t5, input
lb $t5, 2($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
lb $t5, 2($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
lb $t5, 3($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
lb $t5, 3($t7)
andi $t5, $t5, 0x0F # ASCII code to integer
beq $t5, $zero, input
addi $t5, $t5, -9
la $s2, ($zero) # Same counter
la $s2, ($zero) # Same counter
compare_input:
la $t7, input_value
la $t6, guess_value
la $t5, O
la $t4, X
compare_input:
la $t7, input_value
la $t6, guess_value
la $t5, O
la $t4, X
lb $t0, 0($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 0($t6)
lb $t0, 0($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 0($t6)
same1:
sb $0, 0($t7)
sb $t5, 0($s1)
same1:
sb $0, 0($t7)
sb $t5, 0($s1)
- addi $s2, $s2, 1
-different1:
+ addi $s2, $s2, 1
+different1:
lb $t0, 1($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 1($t6)
lb $t0, 1($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 1($t6)
sb $zero, 2($t7)
sb $t5, 2($s1)
addi $s2, $s2, 1
sb $zero, 2($t7)
sb $t5, 2($s1)
addi $s2, $s2, 1
lb $t0, 3($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 3($t6)
beq $t0, $t1, same4
lb $t0, 3($t7)
andi $t0, $t0, 0x0F # ASCII code to integer
lb $t1, 3($t6)
beq $t0, $t1, same4
sb $zero, 3($t7)
sb $t5, 3($s1)
addi $s2, $s2, 1
different4:
sb $zero, 3($t7)
sb $t5, 3($s1)
addi $s2, $s2, 1
different4:
- beq $s2, 4, won
-
-
-print_comp_result:
+ beq $s2, 4, won
+
+
+print_comp_result:
la $a0, newline
li $v0, 4
syscall
la $a0, newline
li $v0, 4
syscall
la $a0, temp_msg
li $v0, 4
syscall
la $a0, temp_msg
li $v0, 4
syscall
won:
la $a0, newline
li $v0, 4
syscall
la $a0, win_msg
li $v0, 4
won:
la $a0, newline
li $v0, 4
syscall
la $a0, win_msg
li $v0, 4
lost:
la $a0, newline
li $v0, 4
lost:
la $a0, newline
li $v0, 4
la $a0, lost_msg
li $v0, 4
la $a0, lost_msg
li $v0, 4