From 8c6fc0c15415b32080a848bbde640e104098cf13 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:18:39 +0200 Subject: Initial drop Add some riscv code Signed-off-by: Carlos Maiolino --- riscv/array_search.s | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 riscv/array_search.s (limited to 'riscv/array_search.s') 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 -- cgit v1.2.3