-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmips3.asm
94 lines (70 loc) · 1.11 KB
/
mips3.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# replace procedure (function)
.data
Arr: .word 21 20 51 83 20 20
length: .word 6
x: .word 20
y: .word 5
index: .word 0
space: .asciiz " "
newline: .asciiz "\n"
.text
main:
la $s0, Arr
lw $s1, length
lw $s2, x
lw $s3, y
move $a0, $s0
move $a1, $s1
move $a2, $s2
move $a3, $s3
jal printArrInt
li $v0, 4
la $a0, newline
syscall
la $a0, Arr
jal replace
la $a0, Arr
jal printArrInt
jal exit
printArrInt:
var:
move $t1, $a1
move $t3, $a0
loop:
beq $t1, 0, ex
lw $t0, 0($t3)
addi $t3, $t3, 4
j print
print:
li $v0, 1
move $a0, $t0
syscall
li $v0, 4
la $a0, space
syscall
subi $t1, $t1, 1
j loop
ex:
jr $ra
replace:
var2:
move $t4, $a2
move $t5, $a3
move $t1, $a1
move $t3, $a0
loop2:
beq $t1, 0, ex2
lw $t0, 0($t3)
subi $t1, $t1, 1
beq $t0, $t4, change
addi $t3, $t3, 4
j loop2
change:
sw $t5, 0($t3)
addi $t3, $t3, 4
j loop2
ex2:
jr $ra
exit:
li $v0, 10
syscall