Skip to content

Instantly share code, notes, and snippets.

@aricneto
Created September 15, 2018 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aricneto/b3bc90ab59ec8f0cdf33fa5f036b9245 to your computer and use it in GitHub Desktop.
Save aricneto/b3bc90ab59ec8f0cdf33fa5f036b9245 to your computer and use it in GitHub Desktop.
main:
addi a0, zero, 7 # function argument (7)
jal ra, fact
jalr x0, x1, 0
fact:
addi sp, sp, -16
sw ra, 8(sp)
sw a0, 0(sp)
addi t0, a0, -1
bge t0, zero, nfact
addi a0, zero, 1
addi sp, sp, 16
jalr x0, x1, 0
nfact:
addi a0, a0, -1
jal ra, fact
addi t1, a0, 0
lw a0, 0(sp)
lw ra, 8(sp)
addi sp, sp, 16
mul a0, a0, t1
jalr x0, x1, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment