From: Jérôme Benoit Date: Wed, 21 Jun 2017 17:13:25 +0000 (+0200) Subject: Beautify a MIPS assembly exercice X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5558d026fc53871fe2622e5bce4722371c3ad293;p=TD_IML.git Beautify a MIPS assembly exercice Signed-off-by: Jérôme Benoit --- diff --git a/TD4/mips1.asm b/TD4/mips1.asm index 81846e5..73da674 100644 --- a/TD4/mips1.asm +++ b/TD4/mips1.asm @@ -1,82 +1,77 @@ .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 ? " + 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' + 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 + 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' + 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 + 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 + 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