TD IML:
[TD_IML.git] / TD4 / mips1.asm
diff --git a/TD4/mips1.asm b/TD4/mips1.asm
new file mode 100644 (file)
index 0000000..81846e5
--- /dev/null
@@ -0,0 +1,82 @@
+.data
+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."
+string_hole: .asciiz "__________"
+input_string: .asciiz "Mot manquant ? "
+.text
+la $a0,string_part_one
+li $v0,4
+syscall
+la $a0,string_hole
+li $v0,4
+syscall
+la $a0,string_part_two
+li $v0,4
+syscall
+la $a0,string_hole
+li $v0,4
+syscall
+la $a0,string_part_three
+li $v0,4
+syscall
+la $a0,n
+li $v0,4
+syscall
+la $a0,input_string
+li $v0,4
+syscall
+li $v0,8
+la $a0,buffer1
+li $a1,20
+syscall
+
+       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
+       addi    $s0, $s0, 1     # increment buffer address
+       j       loop1
+end1:
+       sb      $0, 0($s0)      #replace newline with 0
+
+la $a0,input_string
+li $v0,4
+syscall
+li $v0,8
+la $a0,buffer2
+li $a1,20
+syscall
+
+       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
+       addi    $s0, $s0, 1     # increment buffer address
+       j       loop2
+end2:
+       sb      $0, 0($s0)      #replace newline with 0
+
+la $a0,string_part_one
+li $v0,4
+syscall
+la $a0,buffer1
+li $v0,4
+syscall
+la $a0,string_part_two
+li $v0,4
+syscall
+la $a0,buffer2
+li $v0,4
+syscall
+la $a0,string_part_three
+li $v0,4
+syscall
+
+li $v0,10
+syscall