# Subroutine call
macro .call @lb
# Push previous return addr onto stack
subi r30,r30,1
st r31,r30,0
# Make the call
bt @lb,r31
nop # branch delay slot
# Pop previous return addr
ld r31,r30,0
addi r30,r30,1
end
# Return from sub
macro .ret
jmp r31
end
# define some constants
@start = 10 # Initial value of some variable
@n = 3 # Number of loop iterations
# First instruction of program
ori r2,r0,@start # Load consts into registers
ori r1,r0,@n
out r2
out r1
@loop:
.call @mysub # Call the subroutine
out r2
subi r1,r1,1 # Decrement loop counter
out r1
bne @loop # Branch if still looping
nop # Branch delay slot
nop # Let the pipeline flush before halt
nop
halt # Stop the program
# A subroutine (which doesn't do a lot)
@mysub:
addi r2,r2,1
.ret
nop