Code cleanups.
[TD_IML.git] / TD4 / mips1.asm
... / ...
CommitLineData
1.data
2 buffer1: .space 20
3 buffer2: .space 20
4 n: .asciiz "\n"
5 string_part_one: .asciiz "Le temps est "
6 string_part_two: .asciiz ", je devrais prendre "
7 string_part_three: .asciiz " avant de sortir."
8 string_hole: .asciiz "__________"
9 input_string: .asciiz "Mot manquant ? "
10.text
11 la $a0, string_part_one
12 li $v0, 4
13 syscall
14 la $a0, string_hole
15 li $v0, 4
16 syscall
17 la $a0, string_part_two
18 li $v0, 4
19 syscall
20 la $a0, string_hole
21 li $v0, 4
22 syscall
23 la $a0, string_part_three
24 li $v0, 4
25 syscall
26 la $a0, n
27 li $v0, 4
28 syscall
29 la $a0, input_string
30 li $v0, 4
31 syscall
32 li $v0, 8
33 la $a0, buffer1
34 li $a1, 20
35 syscall
36 la $s0, buffer1 # $s0 contains base address of the string buffer
37 addi $s3, $0, '\n' # $s3 = '\n'
38loop1:
39 lb $s1, 0($s0) # load character into $s0
40 beq $s1, $s3, end1 # break if byte is newline
41 addi $s0, $s0, 1 # increment buffer address
42 j loop1
43end1:
44 sb $0, 0($s0) # replace newline with 0
45 la $a0, input_string
46 li $v0, 4
47 syscall
48 li $v0, 8
49 la $a0, buffer2
50 li $a1, 20
51 syscall
52 la $s0, buffer2 # $s0 contains base address of the string buffer
53 addi $s3, $0, '\n' # $s3 = '\n'
54loop2:
55 lb $s1, 0($s0) # load character into $s0
56 beq $s1, $s3, end2 # break if byte is newline
57 addi $s0, $s0, 1 # increment buffer address
58 j loop2
59end2:
60 sb $0, 0($s0) # replace newline with 0
61 la $a0, string_part_one
62 li $v0, 4
63 syscall
64 la $a0, buffer1
65 li $v0, 4
66 syscall
67 la $a0, string_part_two
68 li $v0, 4
69 syscall
70 la $a0, buffer2
71 li $v0, 4
72 syscall
73 la $a0, string_part_three
74 li $v0, 4
75 syscall
76 li $v0, 10
77 syscall