.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."
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
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
--- /dev/null
+.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