-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.s
150 lines (107 loc) · 2.83 KB
/
code.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
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
# ============== V2 ==============
# addi x1, x0, 7 # x1 = 7 x2 = 0
# # nop
# addi x2, x1, 10 # x1 = 7 x2 = 17
# add x2, x1, x1 # x1 = 7 x2 = 14
# beq x0, x0, shift
# add x2, x1, x1 # x1 = 7 x2 = 14
# nop
# nop
# nop
# nop
# nop
# nop
# shift:
# slli x3, x2, 1 # x3 = 28
# nop
# inf_loop:
# addi x0, x3, 0
# j inf_loop
# nop
# nop
# ============== V3 ==============
# addi x1, x0, 7 # x1 = 7 x2 = 0
# nop
# nop
# add x2, x1, x0 # x1 = 7 x2 = 7
# nop
# nop
# beq x1, x2, shift # if x1 == x2 then shift
# addi x2, x1, 3
# nop
# add x0, x2, x5
# shift:
# slli x3, x2, 1 # x3 = 14
# sub x0, x0, x0
# nop
# ============== GCD algo ==============
# Store data into the RAM
# init:
# addi s1, x0, 8
# # Store the value 10 in memeory location 0x0000_0000 (operand 1)
# addi t1, x0, 10
# sw t1, 0(s1)
# # Store the value 45 in memeory location 0x0000_0004 (operand 2)
# addi t1, x0, 45
# sw t1, 4(s1)
# # Store the value 0 in memeory location 0x0000_0008 (result)
# addi t1, x0, 0
# sw t1, 8(s1)
# main:
# addi a2, x0, 8 # address of data
# lw a1, 4(a2) # load the second integer from RAM in register a1 (b)
# nop
addi a1, x0, 10
# lw a0, 0(a2) # load the first integer from RAM in register a0 (a)
# nop
addi a0, x0, 45
gcd:
jal while_codition # jump to the
while_loop:
blt a0, a1, else # branch to "else" label if a < b
sub a0, a0, a1 # a = a - b
jal while_codition
else:
sub a1, a1, a0 # b = b - a
while_codition:
bne a0, a1 while_loop # while(a != b), do the loob
addi a1, x0, 8 # address of data
sw a0, 8(a1) # store the final result in a0 to RAM (8 bytes offset)
# Display the result on the LEDs
addi x23, x0, 0
sw a0, 0(x23)
inf_loop:
nop
jal inf_loop
# ============== Memory W/R test ==============
# Store the value 10 in memeory location 0x0000_0000 (operand 1)
# addi x10, x0, 8 # x10 = 0x08 (addr)
# addi x11, x0, 7 # x11 = 7 (imm/val)
# # sw x11, 0(x10) # x11[val] -> x10[addr + 0]
# nop
# nop
# nop
# addi x11, x0, 3 # x11 = 3 (imm/val)
# # sw x11, 4(x10) # x11[val] -> x10[addr + 4]
# nop
# nop
# nop
# # lw x1, 0(x10) # x1 <- x10[addr + 0]
# nop
# nop
# # lw x2, 4(x10) # x2 <- x10[addr + 4]
# nop
# nop
# # add x12, x1, x2 # x12 = x1 + x2
# # addi x12, x12, 10
# addi x12, x11, 10
# # Display the result on the LEDs
# # X23 = 0x00
# addi x23, x0, 0
# sw x12, 0(x23) # x12[val] -> x23[addr]
# nop
# nop
# inf_loop:
# nop
# nop
# jal inf_loop