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/pow.s | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 riscv/pow.s (limited to 'riscv/pow.s') diff --git a/riscv/pow.s b/riscv/pow.s new file mode 100644 index 0000000..8aa339d --- /dev/null +++ b/riscv/pow.s @@ -0,0 +1,39 @@ +# Calculate a^b. Where: a0=a, a1=b +# +# Also, this is a good example of how numeric labels can be used +# +# Label 1: can be defined and redefined everywhere, and we can use +# a suffix when referencing it, to specify if we want to reference +# the previous or the next definition of the label, according to the +# current position. 'b' for before 'f' for after. +# +# Ex: +# +# beqz a1, 1f # refers to the symbol 1 defined after this instruction +# + +.globl _start +.section .text +pow: + mv a2, a0 + li a0, 1 + +1: + beqz a1, 1f + mul a0, a0, a2 + addi a1, a1, -1 + j 1b + +1: + ret + +_start: + li a0, 2 + li a1, 3 + jal pow + + # Setup exit ecall + # Return value is already in a0 + + li a7, 93 + ecall -- cgit v1.2.3