From ca13ceb069c1b24f98864e11dcae99133921052c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 22 Jun 2017 10:57:00 +0200 Subject: [PATCH] Add exercice 3 for TD4 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD4/mips1.asm | 26 +++++++++++++------------- TD4/mips2.asm | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 TD4/mips2.asm diff --git a/TD4/mips1.asm b/TD4/mips1.asm index 73da674..7e49dd3 100644 --- a/TD4/mips1.asm +++ b/TD4/mips1.asm @@ -1,7 +1,7 @@ .data - buffer1: .space 20 - buffer2: .space 20 - n: .asciiz "\n" + buffer1: .space 20 + buffer2: .space 20 + n: .asciiz "\n" string_part_one: .asciiz "Le temps est " string_part_two: .asciiz ", je devrais prendre " string_part_three: .asciiz " avant de sortir." @@ -33,15 +33,15 @@ la $a0, buffer1 li $a1, 20 syscall - la $s0, buffer1 # $s0 contains base address of the string buffer + la $s0, buffer1 # $s0 contains base address of the string buffer addi $s3, $0, '\n' # $s3 = '\n' loop1: - lb $s1, 0($s0) # load character into $s0 - beq $s1, $s3, end1 # break if byte is newline + lb $s1, 0($s0) # load character into $s0 + beq $s1, $s3, end1 # break if byte is newline addi $s0, $s0, 1 # increment buffer address - j loop1 + j loop1 end1: - sb $0, 0($s0) #replace newline with 0 + sb $0, 0($s0) # replace newline with 0 la $a0, input_string li $v0, 4 syscall @@ -49,15 +49,15 @@ end1: la $a0, buffer2 li $a1, 20 syscall - la $s0, buffer2 # $s0 contains base address of the string buffer + la $s0, buffer2 # $s0 contains base address of the string buffer addi $s3, $0, '\n' # $s3 = '\n' loop2: - lb $s1, 0($s0) # load character into $s0 - beq $s1, $s3, end2 # break if byte is newline + lb $s1, 0($s0) # load character into $s0 + beq $s1, $s3, end2 # break if byte is newline addi $s0, $s0, 1 # increment buffer address - j loop2 + j loop2 end2: - sb $0, 0($s0) #replace newline with 0 + sb $0, 0($s0) # replace newline with 0 la $a0, string_part_one li $v0, 4 syscall diff --git a/TD4/mips2.asm b/TD4/mips2.asm new file mode 100644 index 0000000..3a0e834 --- /dev/null +++ b/TD4/mips2.asm @@ -0,0 +1,51 @@ +.data +values_number_str: .asciiz "Nombre de valeurs ? " +value_input_str: .asciiz "Valeur entiere ? " +average_str: .asciiz "La moyenne est " +newline: .asciiz "\n" + +.text +main: + jal number_values_input + # counter initialization + la $s0, ($zero) + la $s2, ($zero) +loop: + beq $s0, $s1, end + jal input_value + add $s2, $s2, $t0 + addi $s0, $s0, 1 + j loop +end: + divu $s2, $s1 + mflo $s3 + jal display_average + li $v0, 10 + syscall + +number_values_input: + la $a0, values_number_str + li $v0, 4 + syscall + li $v0, 5 + syscall + move $s1, $v0 + jr $ra + +input_value: + la $a0, value_input_str + li $v0, 4 + syscall + li $v0, 5 + syscall + move $t0, $v0 + jr $ra + +display_average: + la $a0, average_str + li $v0, 4 + syscall + move $a0, $s3 + li $v0, 1 + syscall + jr $ra \ No newline at end of file -- 2.34.1