From: Jérôme Benoit Date: Sun, 17 Sep 2017 10:04:15 +0000 (+0200) Subject: Code cleanups. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=TD_IML.git Code cleanups. Signed-off-by: Jérôme Benoit --- diff --git a/TD3/mips2.asm b/TD3/mips2.asm index 5f2c269..8319145 100644 --- a/TD3/mips2.asm +++ b/TD3/mips2.asm @@ -9,4 +9,4 @@ div $t2,$t1 mflo $t6 mfhi $t7 li $v0,10 -syscall +syscall diff --git a/project/mips1.asm b/project/mips1.asm index 2cba67e..9c86951 100644 --- a/project/mips1.asm +++ b/project/mips1.asm @@ -2,10 +2,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:" -lost_msg: .asciiz "Vous avez perdu !" +lost_msg: .asciiz "Vous avez perdu !" 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" @@ -38,38 +38,38 @@ display_welcome: 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 @@ -81,56 +81,56 @@ 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 + 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 - + 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 - + 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 - + bgez $t5, input + la $s2, ($zero) # Same counter - la $s3 ($zero) + la $s3 ($zero) compare_input: la $t7, input_value la $t6, guess_value la $t5, O la $t4, X - la $t3, tiret - + la $t3, tiret + lb $t0, 0($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 0($t6) @@ -139,8 +139,8 @@ compare_input: 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) @@ -160,21 +160,21 @@ same3: sb $zero, 2($t7) sb $t5, 2($s1) addi $s2, $s2, 1 -different3: +different3: lb $t0, 3($t7) andi $t0, $t0, 0x0F # ASCII code to integer lb $t1, 3($t6) beq $t0, $t1, same4 - j different4 -same4: + j different4 +same4: 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 @@ -190,30 +190,30 @@ print_comp_result: la $a0, temp_msg li $v0, 4 syscall - + addi $s0, $s0, 1 - j loop - + j loop + won: la $a0, newline li $v0, 4 syscall la $a0, win_msg li $v0, 4 - syscall - + syscall + j exit - + lost: la $a0, newline li $v0, 4 - syscall + syscall la $a0, lost_msg li $v0, 4 - syscall - + syscall + j exit - + exit: li $v0, 10 syscall