-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefs.asm
executable file
·158 lines (140 loc) · 3.14 KB
/
defs.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
_PrintInt:
subu $sp, $sp, 8
sw $fp, 8($sp)
sw $ra, 4($sp)
addiu $fp, $sp, 8
li $v0, 1
lw $a0, 4($fp)
syscall
move $sp, $fp
lw $ra, -4($fp)
lw $fp, 0($fp)
jr $ra
_PrintString:
subu $sp, $sp, 8
sw $fp, 8($sp)
sw $ra, 4($sp)
addiu $fp, $sp, 8
li $v0, 4
lw $a0, 4($fp)
syscall
move $sp, $fp
lw $ra, -4($fp)
lw $fp, 0($fp)
jr $ra
_PrintBool:
subu $sp, $sp, 8
sw $fp, 8($sp)
sw $ra, 4($sp)
addiu $fp, $sp, 8
lw $t1, 4($fp)
blez $t1, fbr
li $v0, 4 # system call for print_str
la $a0, TRUE # address of str to print
syscall
b end
fbr: li $v0, 4 # system call for print_str
la $a0, FALSE # address of str to print
syscall
end: move $sp, $fp
lw $ra, -4($fp)
lw $fp, 0($fp)
jr $ra
_Alloc:
subu $sp, $sp, 8
sw $fp, 8($sp)
sw $ra, 4($sp)
addiu $fp, $sp, 8
li $v0, 9
lw $a0, 4($fp)
syscall
move $sp, $fp
lw $ra, -4($fp)
lw $fp, 0($fp)
jr $ra
_StringEqual:
subu $sp, $sp, 8 # decrement sp to make space to save ra, fp
sw $fp, 8($sp) # save fp
sw $ra, 4($sp) # save ra
addiu $fp, $sp, 8 # set up new fp
subu $sp, $sp, 4 # decrement sp to make space for locals/temps
li $v0,0
#Determine length string 1
lw $t0, 4($fp)
li $t3,0
bloop1:
lb $t5, ($t0)
beqz $t5, eloop1
addi $t0, 1
addi $t3, 1
b bloop1
eloop1:
#Determine length string 2
lw $t1, 8($fp)
li $t4,0
bloop2:
lb $t5, ($t1)
beqz $t5, eloop2
addi $t1, 1
addi $t4, 1
b bloop2
eloop2:
bne $t3,$t4,end1 #Check String Lengths Same
lw $t0, 4($fp)
lw $t1, 8($fp)
li $t3, 0
bloop3:
lb $t5, ($t0)
lb $t6, ($t1)
bne $t5, $t6, end1
addi $t3, 1
addi $t0, 1
addi $t1, 1
bne $t3,$t4,bloop3
eloop3: li $v0,1
end1: move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra # return from function
_Halt:
li $v0, 10
syscall
_ReadInteger:
sw $fp, 8($sp) # save fp
sw $ra, 4($sp) # save ra
addiu $fp, $sp, 8 # set up new fp
subu $sp, $sp, 4 # decrement sp to make space for locals/temps
li $v0, 5
syscall
move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra
_ReadLine:
sw $fp, 8($sp) # save fp
sw $ra, 4($sp) # save ra
addiu $fp, $sp, 8 # set up new fp
subu $sp, $sp, 4 # decrement sp to make space for locals/temps
li $a1, 40
la $a0, SPACE
li $v0, 8
syscall
la $t1, SPACE
bloop4:
lb $t5, ($t1)
beqz $t5, eloop4
addi $t1, 1
b bloop4
eloop4:
addi $t1,-1
li $t6,0
sb $t6, ($t1)
la $v0, SPACE
move $sp, $fp # pop callee frame off stack
lw $ra, -4($fp) # restore saved ra
lw $fp, 0($fp) # restore saved fp
jr $ra
.data
TRUE:.asciiz "true"
FALSE:.asciiz "false"
SPACE:.asciiz "Making Space For Inputed Values Is Fun."