diff options
| author | Carlos Maiolino <[email protected]> | 2025-07-10 22:18:39 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-07-10 22:18:39 +0200 |
| commit | 8c6fc0c15415b32080a848bbde640e104098cf13 (patch) | |
| tree | 04a21bd28f9dc82c8e216390d6208ed93b9bcd11 /riscv/array_search.s | |
Initial drop
Add some riscv code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'riscv/array_search.s')
| -rw-r--r-- | riscv/array_search.s | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/riscv/array_search.s b/riscv/array_search.s new file mode 100644 index 0000000..bae9800 --- /dev/null +++ b/riscv/array_search.s @@ -0,0 +1,39 @@ +.section .data +arr: .word 3, 5, 9, 33, 10, 59, 22, 95, 23, 24 + +.section .text +.globl _start + + +# +# a5 - Holds the current array index address +# a1 - The loop counter +# t4 - total elements in the array +# t1 - the index - actually used to calculate the next +# item, always the array member size, can be a loop invariant +# t2 - holds the new index address, I'm pretty sure this can use a5 again +get_largest_number: + la a5, arr + lw a0, (a5) + + li a1, 1 + li t4, 10 + slli t1, a1, 2 + +for: + bge a1, t4, for_exit + add a5, a5, t1 + lw t3, (a5) + blt t3, a0, skip + mv a0, t3 +skip: + addi a1, a1, 1 + j for + +for_exit: + ret + +_start: + call get_largest_number + li a7, 93 + ecall |
