.data 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 !" win_msg: .asciiz "Vous avez gagné !" temp_msg: .asciiz " bien placé" exclamation_point: .asciiz "! " interrogation_point: .asciiz "? " newline: .asciiz "\n" O: .ascii "O" X: .ascii "X" tiret: .ascii "-" compare_buffer: .space 5 input_value: .byte 0:5 guess_value: .byte 0:5 .text main: # show intro and rules display_welcome: la $a0, newline li $v0, 4 syscall la $a0, welcome li $v0, 4 syscall la $a0, newline li $v0, 4 syscall la $a0, play li $v0, 4 syscall la $a0, newline li $v0, 4 syscall 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 sb $a0, 0($t0) li $a1, 8 li $v0, 42 syscall addi $a0, $a0, 1 # Put the integer into the [1-8] range sb $a0, 1($t0) li $a1, 8 li $v0, 42 syscall addi $a0, $a0, 1 # Put the integer into the [1-8] range sb $a0, 2($t0) li $a1, 8 li $v0, 42 syscall addi $a0, $a0, 1 # Put the integer into the [1-8] range sb $a0, 3($t0) generate_sequence_loop_end: la $s0, ($zero) # Initialize loop counter to zero la $s1, compare_buffer loop: beq $s0, 10, lost # ask user for the next input input: la $a0, newline 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 syscall # Make the syscall # check that each input values are in the right range 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, 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 bgez $t5, input lb $t5, 3($t7) andi $t5, $t5, 0x0F # ASCII code to integer beq $t5, $zero, input addi $t5, $t5, -9 bgez $t5, input la $s2, ($zero) # Same counter la $s3 ($zero) compare_input: la $t7, input_value la $t6, guess_value la $t5, O la $t4, X la $t3, tiret lb $t0, 0($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 0($t6) beq $t0, $t1, same1 j different1 same1: sb $0, 0($t7) sb $t5, 0($s1) addi $s2, $s2, 1 different1: lb $t0, 1($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 1($t6) beq $t0, $t1, same2 j different2 same2: sb $zero, 1($t7) sb $t5, 1($s1) addi $s2, $s2, 1 different2: lb $t0, 2($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 2($t6) beq $t0, $t1, same3 j different3 same3: sb $zero, 2($t7) sb $t5, 2($s1) addi $s2, $s2, 1 different3: lb $t0, 3($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 3($t6) beq $t0, $t1, same4 j different4 same4: sb $zero, 3($t7) sb $t5, 3($s1) addi $s2, $s2, 1 different4: beq $s2, 4, won print_comp_result: la $a0, newline li $v0, 4 syscall la $a0, ($s0) li $v0, 1 syscall la $a0, exclamation_point li $v0, 4 syscall la $a0, ($s2) li $v0, 1 syscall la $a0, temp_msg li $v0, 4 syscall addi $s0, $s0, 1 j loop won: la $a0, newline li $v0, 4 syscall la $a0, win_msg li $v0, 4 syscall j exit lost: la $a0, newline li $v0, 4 syscall la $a0, lost_msg li $v0, 4 syscall j exit exit: li $v0, 10 syscall