Skip to content

Commit 0c66e48

Browse files
committed
Replace mul in write_matrix.s
Refactor `write_matrix.s` to avoid using the `mul` instruction by implementing a custom solution for multiplication. This approach is inspired by the cumulative addition/subtraction logic used in the earlier `dot` operation implementation. Negative numbers are not handled here, as both the number of rows and columns are guaranteed to be positive.
1 parent c818213 commit 0c66e48

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/write_matrix.s

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ write_matrix:
6363

6464
# mul s4, s2, s3 # s4 = total elements
6565
# FIXME: Replace 'mul' with your own implementation
66-
66+
li t5, 0
67+
68+
accumulate:
69+
add t5,t5,s2
70+
addi s3, s3, -1
71+
bne s3, zero, accumulate
72+
73+
mv s4, t5
74+
6775
# write matrix data to file
6876
mv a0, s0
6977
mv a1, s1 # matrix data pointer

0 commit comments

Comments
 (0)