Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define(n_r, i0)
- define(j_r, l0)
- define(prod_r, i0)
- define(local_n_r, l1)
- .global main
- main:
- save %sp, -96, %sp
- call factorial
- mov 4, %o0
- b skip
- mov 1, %g1
- .global factorial
- factorial:
- save %sp, -64, %sp
- mov %n_r, %local_n_r ! store int n in local variable
- mov 1, %prod_r ! set product to 1
- b fortest
- mov 1, %j_r ! set j to 1
- for:
- call .mul ! n = n * j
- mov %j_r, %o1
- mov %o0, %prod_r ! move the resulting answer into N
- inc %j_r ! j++
- fortest:
- cmp %j_r, %local_n_r ! check that j <= N
- ble,a for
- mov %prod_r, %o0 ! move n in o0 so that call to .mul can occur
- ret
- restore ! restore the window and return to calling instruction
- skip:
- ta 0
- ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement