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/pow.s | |
Initial drop
Add some riscv code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'riscv/pow.s')
| -rw-r--r-- | riscv/pow.s | 39 |
1 files changed, 39 insertions, 0 deletions
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 |
