Skip to content

Instantly share code, notes, and snippets.

@pureexe
Created September 9, 2019 06:03
Show Gist options
  • Select an option

  • Save pureexe/a7c098134304d8876fa75acf1ba17ea2 to your computer and use it in GitHub Desktop.

Select an option

Save pureexe/a7c098134304d8876fa75acf1ba17ea2 to your computer and use it in GitHub Desktop.
# somehow this program need header to make it runable
# if it not have this header the program will loop forever
.text
addi t6, t6 ,1
beq t6, x0 ,finish
addi t6, x0 ,-1
# Set value n to x10 by yourself here!
addi x10, x0, 3
# here is the original code
# which already convert from 64-bit to 32 bit
fact:
addi sp,sp,-8
sw x10,4(sp)
sw x1,0(sp)
addi x5,x10,-1
bge x5,x0,L1
addi x10,x0,1
addi sp,sp,8
jalr x0,0(x1)
L1: addi x10,x10,-1
jal x1,fact
addi x6,x10,0
lw x1,0(sp)
lw x10,4(sp)
addi sp,sp,8
mul x10,x10,x6
jalr x0,0(x1)
# and this program also need to print output
# which is store in x10
finish:
addi t0, x10, 0
addi a0, x0, 1
addi a1, t0, 0
ecall # print integer ecall
addi a0, x0, 10
ecall # terminate ecall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment