Skip to content

Commit 6bd7b55

Browse files
committed
Implement argmax function
Completed the implementation of the `argmax` function. It scans an integer array to find the maximum value and returns the 0-based index of its first occurrence. Changes include: - Implemented the main loop to iterate through the array. - Updated maximum value (`t0`) and index (`t1`) when a larger element is found. - Ensured the function terminates gracefully using the `end` label, with the result stored in `a0`.
1 parent 3a0d410 commit 6bd7b55

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/argmax.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ argmax:
3131
li t2, 1
3232
loop_start:
3333
# TODO: Add your own implementation
34+
bge t2, a1, end
35+
36+
slli t3, t2, 2
37+
add t4, a0, t3
38+
lw t5, 0(t4)
39+
40+
ble t5, t0, next_element #<= nochange
41+
42+
mv t0, t5
43+
mv t1, t2
44+
45+
next_element:
46+
addi t2, t2, 1
47+
j loop_start
48+
end:
49+
mv a0, t1
50+
jr ra
3451

3552
handle_error:
3653
li a0, 36

0 commit comments

Comments
 (0)