Advertisement
asharma

Factorial

Feb 26th, 2019
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main:
  2.     ecall x10, x0, 5
  3.     addi  sp, sp, 1600
  4.     addi x20, x0, 1    
  5.     jal x1, fact
  6.    
  7.     # jal x0, exit
  8.     beq x0, x0, exit
  9.  
  10. fact:
  11.     addi    sp, sp, -16         # $t0 = $t1 + 0
  12.     sd      x1, 8(sp)
  13.     sd      x10, 0(sp)
  14.  
  15.     addi    x5, x10, 0
  16.     bge     x5, x20, L1 #  # x >= 1
  17.  
  18.     addi    x10, x0, 1
  19.     addi    sp, sp, 16
  20.     jalr    x0, 0(x1)
  21.    
  22. L1:        
  23.     addi    x10, x10, -1
  24.     jal     x1, fact
  25.  
  26.     addi    x6, x10, 0
  27.     ld      x10, 0(sp)
  28.     ld      x1, 8(sp)
  29.     addi    sp, sp, 16
  30.     mul     x10, x10, x6
  31.  
  32.     jalr    x0, 0(x1)
  33.  
  34.  
  35. exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement