Advertisement
Guest User

Untitled

a guest
Apr 12th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SPARK 0.84 KB | None | 0 0
  1. define(n_r, i0)
  2. define(j_r, l0)
  3. define(prod_r, i0)
  4. define(local_n_r, l1)
  5.  
  6. .global main
  7.  
  8. main:
  9.     save    %sp, -96, %sp
  10.  
  11.     call    factorial
  12.     mov     4, %o0
  13.  
  14.     b       skip
  15.     mov     1, %g1
  16.  
  17.  
  18. .global factorial
  19.  
  20. factorial:
  21.     save    %sp, -64, %sp
  22.     mov     %n_r, %local_n_r ! store int n in local variable
  23.  
  24.     mov     1, %prod_r  ! set product to 1
  25.  
  26.     b       fortest
  27.     mov     1, %j_r ! set j to 1
  28.  
  29. for:
  30.     call    .mul        ! n = n * j
  31.     mov     %j_r, %o1
  32.  
  33.     mov     %o0, %prod_r   ! move the resulting answer into N
  34.     inc     %j_r        ! j++
  35.  
  36. fortest:
  37.     cmp     %j_r, %local_n_r ! check that j <= N
  38.     ble,a   for
  39.     mov     %prod_r, %o0 ! move n in o0 so that call to .mul can occur
  40.  
  41.     ret
  42.     restore ! restore the window and return to calling instruction
  43.  
  44. skip:
  45.     ta      0
  46. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement