as1 - # store $ra addi $t0, $0, 2 slt $t0, $a1, $t0 # a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Main: M li $a0, 0x100 li $a1, 0 li $t0, 3 li $t1, 2 li $t4, 0 Carray_loop: slt $t2, $a1, $t1 beq $t2, $0, Exit_loop sll $t2, $a1, 2 add $t2, $t2, $a0 mult $a1, $t0 mflo $t3 sw $t3, 0($t2) addi $a1, $a1, 1 j Carray_loop j Exit_loop: lw $t1, 4($a0) sw $t1, 4($a0) lw $t2, 8($a0) sw $t2, 8($a0) add $t3, $t1, $t2 addi $t4, $t4, 2 div $t3, $t4 mflo $a1 m jal factorial add $a0, $v0, $0 a factorial: addi $sp, $sp, -8 # make room sw $a1, 4($sp) # store $a1 sw $ra, 0($sp)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # store $ra addi $t0, $0, 2 slt $t0, $a1, $t0 # a <= 1 ? beq $t0, $0, else # no: go to else addi $v0, $0, 1 # yes: return 1 addi $sp, $sp, 8 # restore $sp jr $ra # return else: addi $a1, $a1, -1 # n = n - 1 jal factorial # recursive call lw $ra, 0($sp) # restore $ra lw $a1, 4($sp) # restore $a1 addi $sp, $sp, 8 # restore $sp mult $v0, $a1 # n * factorial(n-1) jr $ra # return...
View Full Document

Ask a homework question - tutors are online