From: Jérôme Benoit Date: Wed, 21 Jun 2017 11:16:38 +0000 (+0200) Subject: TD IML: X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9cb0c82389b58f164f115c9fb407e7aacbd77fc6;p=TD_IML.git TD IML: Add two MIPS assembler exercices. Signed-off-by: Jérôme Benoit --- diff --git a/TD2/exercise3/exercise.c b/TD2/exercise3/exercise.c index 1d20fc5..9459ab1 100644 --- a/TD2/exercise3/exercise.c +++ b/TD2/exercise3/exercise.c @@ -29,6 +29,7 @@ int main() { } 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); } diff --git a/TD3/mips2.asm b/TD3/mips2.asm index a4689d7..5f2c269 100644 --- a/TD3/mips2.asm +++ b/TD3/mips2.asm @@ -8,5 +8,5 @@ mflo $t5 div $t2,$t1 mflo $t6 mfhi $t7 -la $v0,10 -syscall \ No newline at end of file +li $v0,10 +syscall diff --git a/TD3/mips3.asm b/TD3/mips3.asm index 2f3018c..9a7239d 100644 --- a/TD3/mips3.asm +++ b/TD3/mips3.asm @@ -57,5 +57,5 @@ syscall add $a0,$t7,$zero li $v0,1 syscall -la $v0,10 +li $v0,10 syscall diff --git a/TD3/mips4.asm b/TD3/mips4.asm new file mode 100644 index 0000000..33e6679 --- /dev/null +++ b/TD3/mips4.asm @@ -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 index 0000000..81846e5 --- /dev/null +++ b/TD4/mips1.asm @@ -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