1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|