Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- num: .word 6 # Number for factorial
- fact: .word 0 # Store result
- .text
- _start:
- la x5, num # Load address of num
- lw x5, 0(x5) # Load num into x5
- li x6, 1 # Initialize result to 1
- factorial_loop:
- li x7, 0 # Load 0 for comparison
- bne x5, x7, multiply # If x5 != 0, jump to multiply
- j end_loop # If x5 == 0, exit loop
- multiply:
- mul x6, x6, x5 # result *= n (x5)
- addi x5, x5, -1 # n--
- j factorial_loop # Loop again
- end_loop:
- la x8, fact # Load address of fact
- sw x6, 0(x8) # Store result in memory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement