-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlabwork.S
More file actions
187 lines (172 loc) · 3.15 KB
/
labwork.S
File metadata and controls
187 lines (172 loc) · 3.15 KB
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
# labwork.S
# Written 2015-2017 by F Lundevall
# Skeleton file for IS1200/IS1500 lab 1.
# The macros PUSH and POP are in the public domain.
# Please add your own code at the end of the file.
#
# Please keep the two macros PUSH and POP unchanged
#
.global delay
.global time2string
.global hexasc
.global enable_interrupt
.data
.align 2
mytime: .word 0x5957
timstr: .ascii ""
.text
.macro PUSH reg
addi $sp,$sp,-4
sw \reg, 0($sp)
.endm
.macro POP reg
lw \reg, 0($sp)
addi $sp,$sp,4
.endm
#
# Please add your own code below this line
#
main:
# print timstr
la $a0,timstr
li $v0,4
syscall
nop
# wait a little
li $a0,60
jal delay
nop
# call tick
la $a0,mytime
jal tick
nop
# call your function time2string
la $a0,timstr
la $t0,mytime
lw $a1,0($t0)
jal time2string
nop
# print a newline
li $a0,10
li $v0,11
syscall
nop
# go back and do it all again
j main
nop
# tick: update time pointed to by $a0
tick: lw $t0,0($a0) # get time
addiu $t0,$t0,1 # increase
andi $t1,$t0,0xf # check lowest digit
sltiu $t2,$t1,0xa # if digit < a, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0x6 # adjust lowest digit
andi $t1,$t0,0xf0 # check next digit
sltiu $t2,$t1,0x60 # if digit < 6, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0xa0 # adjust digit
andi $t1,$t0,0xf00 # check minute digit
sltiu $t2,$t1,0xa00 # if digit < a, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0x600 # adjust digit
andi $t1,$t0,0xf000 # check last digit
sltiu $t2,$t1,0x6000 # if digit < 6, okay
bnez $t2,tiend
nop
addiu $t0,$t0,0xa000 # adjust last digit
tiend: sw $t0,0($a0) # save updated result
jr $ra # return
nop
delay:
PUSH $ra
whileloop:
slt $t0,$zero,$a0 # a0 register is the argument for delay . if ms > 0 then t0 = 1 which mean
bne $t0,1,done # if t0=! 1 which means ms<=0 leave the loop
nop
addi $a0,$a0,-1
la $t1, ($zero)
la $t2,($zero)
forloop:
#do nothing
nop
addi $t1,$t1,1 # i++
slti $t2,$t1,5500# i<4711 ms change dealy in ms
bne $t2, $zero, forloop # if t2=!0 then
nop
j whileloop
nop
done:
POP $ra
jr $ra
nop
time2string:
PUSH $ra # push the return reg
PUSH $s0
PUSH $s1
move $s0,$a1 # move the value of a1 to t1 a1= mytime
move $s1,$a0
add $t0,$zero,$zero
loopit:
and $a0,$s0,0xF000
srl $a0,$a0,12 # shift the number to the first byte
sll $s0,$s0,4 # shift 1 byte to left to get the next from the last number in time
jal hexasc # convert the number to hex
nop
sb $v0,0($s1) # store the number in reg
addi $s1,$s1,0x1 # next address to save the number in
addi $t0,$t0,1 # the loop counter
beq $t0, 2, colon # if we printed the second number we jump to the colon
nop
bne $t0, 4, loopit
nop
beq $v0,0x32,two
nop
end:
li $t1,0x00
sb $t1,0($s1)
move $t1,$zero
POP $s1
POP $s0
POP $ra
move $t0,$zero
jr $ra
nop
enable_interrupt:
ei
jr $ra
nop
colon:
li $t1,0x3A
sb $t1,0($s1)
addi $s1,$s1,0x1
move $t1,$zero
j loopit
nop
two:
sub $s1,$s1,1
li $t1,0x54
sb $t1,0($s1)
addi $s1,$s1,0x1
li $t1,0x57
sb $t1,0($s1)
addi $s1,$s1,0x1
li $t1,0x4F
sb $t1,0($s1)
addi $s1,$s1,0x1
move $t1,$zero
j end
nop
# you can write your code for subroutine "hexasc" below this line
#
hexasc:
andi $a0,$a0,0xF
addi $v0,$a0,0x30
blt $a0, 10, finish
nop
addi $v0, $v0, 0x7 #jump to A to F in ASCII
finish:
jr $ra
nop