TD IML:
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 21 Jun 2017 11:16:38 +0000 (13:16 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 21 Jun 2017 11:16:38 +0000 (13:16 +0200)
Add two MIPS assembler exercices.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD2/exercise3/exercise.c
TD3/mips2.asm
TD3/mips3.asm
TD3/mips4.asm [new file with mode: 0644]
TD4/mips1.asm [new file with mode: 0644]

index 1d20fc50192850bce84bb111c0509dcf84da7ba3..9459ab1e87fefdbbcd5c06427b689ea0cda4e7da 100644 (file)
@@ -29,6 +29,7 @@ int main() {
     } else {
         close(pipefd[1]);
         printf("[%d] REDIRECTION: \n", getpid());
     } else {
         close(pipefd[1]);
         printf("[%d] REDIRECTION: \n", getpid());
+        //determine the pipe size to avoid this kind of code 
         while (read(pipefd[0], &tmpbuf, 1) > 0) {
             write(STDOUT_FILENO, &tmpbuf, 1);
         }
         while (read(pipefd[0], &tmpbuf, 1) > 0) {
             write(STDOUT_FILENO, &tmpbuf, 1);
         }
index a4689d7afc1b0bb0128c4b847d15ca6593342d6f..5f2c269204fe42ee9359c7f63c0133f2dddbf36b 100644 (file)
@@ -8,5 +8,5 @@ mflo $t5
 div $t2,$t1
 mflo $t6
 mfhi $t7
 div $t2,$t1
 mflo $t6
 mfhi $t7
-la $v0,10
-syscall 
\ No newline at end of file
+li $v0,10
+syscall 
index 2f3018c9ecdcdcdbf1b6670815007e7e3059b540..9a7239dd96de899911b6453716d1c3a42a05fa63 100644 (file)
@@ -57,5 +57,5 @@ syscall
 add $a0,$t7,$zero
 li $v0,1
 syscall
 add $a0,$t7,$zero
 li $v0,1
 syscall
-la $v0,10
+li $v0,10
 syscall 
 syscall 
diff --git a/TD3/mips4.asm b/TD3/mips4.asm
new file mode 100644 (file)
index 0000000..33e6679
--- /dev/null
@@ -0,0 +1,42 @@
+.data
+msg_input: .asciiz "Valeur entiere ? "
+msg_addition: .asciiz "Addition des valeurs: "
+msg_continue: .asciiz "Continuer ? (O/n) "
+n: .asciiz "\n"
+.text
+start:
+la $a0,n
+li $v0,4
+syscall
+la $a0,msg_input
+li $v0,4
+syscall
+li $v0,5
+syscall
+add $t0,$v0,$zero
+la $a0,msg_input
+li $v0,4
+syscall
+li $v0,5
+syscall
+add $t1,$v0,$zero
+la $a0,msg_addition
+li $v0,4
+syscall
+add $a0,$t0,$t1
+li $v0,1
+syscall
+la $a0,n
+li $v0,4
+syscall
+la $a0,msg_continue
+li $v0,4
+syscall
+li $v0,12
+syscall
+# ascii code for O
+beq $v0,079,start
+# ascii code for o
+beq $v0,111,start
+li $v0,10
+syscall
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