} 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);
}
--- /dev/null
+.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