• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Oct 16th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #
2. # Sum of Absolute Differences Algorithm
3. #
4. # Authors:
5. #   X Y, Z Q
6. #
7. #
8.
9. .text
10.
11.
12. main:
13.
14.
15. # Initializing data in memory...
16. # Store in \$s0 the address of the first element in memory
17.     # lui sets the upper 16 bits of thte specified register
18.     # ori the lower ones
19.     # (to be precise, lui also sets the lower 16 bits to 0, ori ORs it with the given immediate)
20.       # TODO1: initilize the rest of the memory.
21.          lui     \$s0, 0x0000 # Address of first element in the vector
22.          ori     \$s0, 0x0000
23.          addi   \$t0, \$0, 5  # left_image
24.          sw      \$t0, 0(\$s0)
25.          addi   \$t0, \$0, 16 # left_image
26.          sw      \$t0, 4(\$s0)
27.          addi   \$t0, \$0, 7  # left_image
28.          sw      \$t0, 8(\$s0)
29.          addi   \$t0, \$0, 1  # left_image
30.          sw      \$t0, 12(\$s0)
31.          addi   \$t0, \$0, 1  # left_image
32.          sw      \$t0, 16(\$s0)
33.          addi   \$t0, \$0, 13 # left_image
34.          sw      \$t0, 20(\$s0)
35.          addi   \$t0, \$0, 2  # left_image
36.          sw      \$t0, 24(\$s0)
37.          addi   \$t0, \$0, 8  # left_image
38.          sw      \$t0, 28(\$s0)
39.          addi   \$t0, \$0, 10 # left_image
40.          sw      \$t0, 32(\$s0)
41.          addi   \$t0, \$0, 4  # right_image
42.          sw      \$t0, 36(\$s0)
43.          addi   \$t0, \$0, 15 # right_image
44.          sw      \$t0, 40(\$s0)
45.          addi   \$t0, \$0, 8  # right_image
46.          sw      \$t0, 44(\$s0)
47.          addi   \$t0, \$0, 0  # right_image
48.          sw      \$t0, 48(\$s0)
49.          addi   \$t0, \$0, 2  # right_image
50.          sw      \$t0, 52(\$s0)
51.          addi   \$t0, \$0, 12 # right_image
52.          sw      \$t0, 56(\$s0)
53.          addi   \$t0, \$0, 3  # right_image
54.          sw      \$t0, 60(\$s0)
55.          addi   \$t0, \$0, 7  # right_image
56.          sw      \$t0, 64(\$s0)
57.          addi   \$t0, \$0, 11 # right_image
58.          sw      \$t0, 68(\$s0)
59.          # .....
60.
61.
62.
63.     # TODO4: Loop over the elements of left_image and right_image
64.
65.     addi \$t5, \$0, 0 # \$s1 = i = 0
66.     addi \$t6, \$0, 9 # \$s2 = image_size = 9
67.     j loop
68.
69. loop:
70.
71.     # Check if we have traverse all the elements
73.
74.
75.     # ....
76.
77.
78.     # Load left_image{i} and put the value in the corresponding register
79.     # before doing the function call
80.     # ....
81.
82.
83.     # Load right_image{i} and put the value in the corresponding register
84.
85.     # ....
86.
87.     # Call abs_diff
88.     j abs_diff
89.     # ....
90.
91.     #Store the returned value in sad_array[i]
92.
93.     # ....
94.
95.
96.     # Increment variable i and repeat loop:
97.
98.     # ...
99.
100.
101.
102. end_loop:
103.
104.     #TODO5: Call recursive_sum and store the result in \$t2
106.     #of the function call)and store in the corresponding register
107.     j recursive_sum
108.     # ...
109.
110.     # Prepare the second argument of the function call: the size of the array
111.
112.     #.....
113.
114.     # Call to funtion
115.
116.     # ....
117.
118.
119.     #Store the returned value in \$t2
120.
121.     # .....
122.
123.
124. end:
125.     j   end # Infinite loop at the end of the program.
126.
127.
128.
129.
130. # TODO2: Implement the abs_diff routine here, or use the one provided
131.
132. abs_diff:
133.         lw \$t0, 0(\$s0)
134.         lw \$t1, 36(\$s0)
135.         sub \$t2, \$t0, \$t1
136.         abs \$t2, \$t2
137.         sw \$t2, 72(\$s0) #0
138.         lw \$t0, 4(\$s0)
139.         lw \$t1, 40(\$s0)
140.         sub \$t2, \$t0, \$t1
141.         abs \$t2, \$t2
142.         sw \$t2, 76(\$s0) #1
143.         lw \$t0, 8(\$s0)
144.         lw \$t1, 44(\$s0)
145.         sub \$t2, \$t0, \$t1
146.         abs \$t2, \$t2
147.         sw \$t2, 80(\$s0) #2
148.         lw \$t0, 12(\$s0)
149.         lw \$t1, 48(\$s0)
150.         sub \$t2, \$t0, \$t1
151.         abs \$t2, \$t2
152.         sw \$t2, 84(\$s0) #3
153.         lw \$t0, 16(\$s0)
154.         lw \$t1, 52(\$s0)
155.         sub \$t2, \$t0, \$t1
156.         abs \$t2, \$t2
157.         sw \$t2, 88(\$s0) #4
158.         lw \$t0, 20(\$s0)
159.         lw \$t1, 56(\$s0)
160.         sub \$t2, \$t0, \$t1
161.         abs \$t2, \$t2
162.         sw \$t2, 92(\$s0) #5
163.         lw \$t0, 24(\$s0)
164.         lw \$t1, 60(\$s0)
165.         sub \$t2, \$t0, \$t1
166.         abs \$t2, \$t2
167.         sw \$t2, 96(\$s0) #6
168.         lw \$t0, 28(\$s0)
169.         lw \$t1, 64(\$s0)
170.         sub \$t2, \$t0, \$t1
171.         abs \$t2, \$t2
172.         sw \$t2, 100(\$s0) #7
173.         lw \$t0, 32(\$s0)
174.         lw \$t1, 68(\$s0)
175.         sub \$t2, \$t0, \$t1
176.         abs \$t2, \$t2
177.         sw \$t2, 104(\$s0) #8
178.
179.
180. # TODO3: Implement the recursive_sum routine here, or use the one provided
181.
182. recursive_sum:
185.             sw   \$ra, 4(\$sp)        # Save return
186.             lw \$t1, 72(\$s0)         #Inicio del vector SAD
187.             lw \$t2, 0(\$0)
188.             Q: beqz \$t0, out
189.             REC: