-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kernel.asm
187 lines (149 loc) · 2.95 KB
/
Kernel.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# ; syscall:
# ; beq $v0 $0 main #if $vo is 0, jump to main addi $k1, $0, 12
# ; beq $v0 $k1 syscall12
# ; addi $k1 $0 9
# ; beq $v0 $k1 syscall9
# ; addi $k1 $0 10
# ; beq $v0 $k1 syscall10
# ; sycall9:
# ; # your assembly goes here
# ; syscall10:
# ; j syscall10
# ; syscall12:
.globl main
syscall:
beq $v0, $0, main
addi $k1, $0, 10
beq $v0, $k1, syscall10
addi $k1, $0, 12
beq $v0, $k1, syscall12
addi $k1, $0, 80
beq $v0, $k1, syscall80
addi $k1, $0, 5
beq $v0, $k1, syscall5
addi $k1, $0, 77
beq $v0, $k1, syscall77
addi $k1, $0, 65
beq $v0, $k1, syscall65
# END PROGRAM
syscall10:
j syscall10
jr $k0
# PRINT CHAR
syscall12:
lw $k1, 16($0) #we is 0, access to 16
beq $k1, $0, do_nothing #
lw $v0, 20($0)
sw $0, 16($0)
j finish
do_nothing:
addi $v0, $0, 0
finish:
jr $k0
# READ INTEGER
syscall5:
addi $sp, $sp, -4
sw $t0, 0($sp)
addi $v1, $0, 0
read:
addi $sp, $sp, -4
sw $k0, 0($sp)
addi $v0, $0, 12
syscall
lw $k0, 0($sp)
addi $sp, $sp, 4
beq $v0, $0, read
#lw $k1, 16($0)
#beq $k1, $0, read
addi $t0, $0, 32
beq $v0, $t0, stop
beq $v1, $0, miss_mult
addi $k1, $0, 10
mult $v1, $k1
mflo $v1
miss_mult:
#sw $0, 16($0)
#lw $v0, 20($0)
addi $k1, $0, 48
bne $v0, $k1, not0
addi $v1, $v1, 0
j found_int
not0:
addi $k1, $k1, 1
bne $v0, $k1, not1
addi $v1, $v1, 1
j found_int
not1:
addi $k1, $k1, 1
bne $v0, $k1, not2
addi $v1, $v1, 2
j found_int
not2:
addi $k1, $k1, 1
bne $v0, $k1, not3
addi $v1, $v1, 3
j found_int
not3:
addi $k1, $k1, 1
bne $v0, $k1, not4
addi $v1, $v1, 4
j found_int
not4:
addi $k1, $k1, 1
bne $v0, $k1, not5
addi $v1, $v1, 5
j found_int
not5:
addi $k1, $k1, 1
bne $v0, $k1, not6
addi $v1, $v1, 6
j found_int
not6:
addi $k1, $k1, 1
bne $v0, $k1, not7
addi $v1, $v1, 7
j found_int
not7:
addi $k1, $k1, 1
bne $v0, $k1, not8
addi $v1, $v1, 8
j found_int
not8:
addi $k1, $k1, 1
bne $v0, $k1, stop
addi $v1, $v1, 9
found_int:
j read
stop:
addi $v0, $v1, 0
lw $t0, 0($sp)
addi $sp, $sp, 4
jr $k0
# Heap Allocation
syscall9:
lw $k1, 0($a0) # load current heap pointer
add $k1, $k1, $a1 #increase heap pointer value by set amount
sw $k1, 0($a0) #store new pointer value
jr $k0
# syscall80:
# sw $a0, 32($0)
# sw $a1, 36($0)
# sw $a2, 40($0)
# sw $0, 44($0)
# #addi $v0, $0, 18
# jr $k0
# syscall77:
# sw $a0, 112($0)
# jr $k0
# syscall65:
# addi $sp, $sp, -8
# sw $t0, 0($sp)
# sw $t1, 4($sp)
# lw $t0, 48($0)
# lw $t1, 52($0)
# addi $v0, $t0, 0
# addi $v1, $t1, 0
# lw $t0, 0($sp)
# lw $t1, 4($sp)
# addi $sp, $sp, 8
# jr $k0