-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.S
103 lines (86 loc) · 1.36 KB
/
delay.S
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
# 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
#
.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
#
.global delay
.global time2string
.data
.text
hexasc:
andi $a0,$a0, 0xf #Checks 4 LSB
addi $v0,$a0,0x30
jr $ra
nop
delay:
PUSH $s3
li $s3, 470000
li $t6, 0
li $t7, 0
j loop
nop
loop:
beq $t7, $a0, end
nop
sub $a0, $a0, 1
j loop2
nop
loop2:
beq $t6, $s3, loop
nop
addi $t6, $t6, 1
j loop2
nop
end:
POP $s3
jr $ra
nop
time2string:
PUSH $s0
PUSH $s1
PUSH $ra
PUSH $a0
add $s0,$a1,$0 #Saves time info to t0
add $s1,$a0,$0 #Saves time info address to t1
srl $a0,$s0,12 # Första minut-talet
jal hexasc
nop
sb $v0, 0($s1)
srl $a0,$s0,8 # Andra minut-talet
jal hexasc
nop
sb $v0, 1($s1)
li $t4, 0x3A #Contains ":"
nop
sb $t4, 2($s1) # Lägger till kolon
srl $a0,$s0,4 # första sekund-talet
jal hexasc
nop
sb $v0, 3($s1)
add $a0, $s0, $zero # andra sekund-talet
jal hexasc
nop
sb $v0, 4($s1)
li $t5,0x00
nop
sb $t5, 5($s1)
POP $a0
POP $ra
POP $s1
POP $s0
jr $ra
nop