Assignment Instructions:
1) The Factorial
The factorial of a non-negative integer ??, denoted by ??!, isthe product of all positive integers less than or equal to ??. Thetextbook has an example of a recursive MIPS implementation offactorial. Additionally, a simplified version of the MIPS assemblylanguage recursive implementation of the factorial function isattached. Trace the factorial example carefully using QTSPIM
2) Recursive definition of multiplication
The function ??????????(??, ??) for two positive integers 1 ???, and 1 ? ??, is defined as the following:
??????????(??, 1) = ??; ??????????(??, ??) = ?? + ??????????(??,?? ? 1)
Write a recursive version of ??????????() in C or C++ and apseudo C program (based on chapter 2 in the book) then use theseprograms to develop a MIPS program that gets as input two integers0 < ?? ? 255, and 0 < ?? ? 255, and returns the result of??????????(??, ??) in $v1.
Your deliverable should be the pseudo C and the assembly levelfunction
Given code file one:
//copyable code
1.
.data
messagestr: .asciiz \"Enter Number: \"
.text
.globl main
main:
la $a0, messagestr
#load the data
li $v0, 4
#system call
syscall
#load the data
li $v0, 5
#system call
syscall
#move the data
move $a0,$v0 Â Â
jal factorial
move $a0,$v0 Â Â
li $v0,1 Â Â
syscall
li $v0,10
syscall
factorial:
#add the value
addi $sp,$sp,-8
#store the value Â
sw $s0,0($sp)
#store the value  Â
sw $ra,4($sp)
#move the data
move $s0,$a0
#load the data  Â
li $v0,0x00000001 # 1
beq $s0,$v0,loop2
#branch instruction Â
addi $a0,$s0,-1 Â Â
jal factorial
#multiply the data
mult $v0,$s0 Â Â
mflo $v0 Â Â
j loop3
#loop
loop2:
li $v0,0x00000001
loop3:
lw $ra,4($sp) Â Â
lw $s0,0($sp) Â Â
addi $sp,$sp,8 Â Â
jr $ra # return
Given code file two:
###################################################################################### Functional Description: Main program to test Factorial function# Enter a negative number to terminate run##################################################################################### .data .align 2 .textmain: addiu $sp, $sp, -8 # Allocate spacemloop: li $v0, 4 # Get value for N sw $v0, 0 ($sp) jal Fac # Call factorial or $v1, $v0, $0 addiu $sp, 8 # Deallocate space li $v0, 10 syscall###################################################################################### Functional Description: Recursive Factorial Fac (N: in, N! :out)#####################################################################################Fac: lw $a0, 0 ($sp) addiu $sp, $sp, -16 # Allocate sw $ra, 12 ($sp) # Save return address sw $a0, 8($sp) slti $t0, $a0, 2 # If N is 1 or 0, then return the value 1 beqz $t0, Go li $v0, 1 b facretGo: addi $a0, $a0, -1 # sw $a0, 0 ($sp) # Pass N-1 to factorial function jal Fac # Recursive call lw $v0, 4($sp) # Get (N-1) ! back. lw $ra, 12 ($sp) lw $a0, 8 ($sp) mult $v0, $a0 # N* (N-1) ! mflo $v0facret: addiu $sp, $sp, 16 # Deallocate sw $v0, 4 ($sp) jr $ra