Question

In: Computer Science

Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the...

Write a MIPS Assembly program function to calculate the factorial of an input number. Analyze the program for the value 10 and compute the Execution time in a MIPS processor at 2.4GHz. The CPI is 1.

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

.data
printmsg: .asciiz " \nEnter a number to find factorial : "
printmsg2: .asciiz "Factorial of the number is : "
.text
.globl main
main:
doAgain :
la $a0,printmsg # Load the address of prompt
li $v0,4 # The string print service is specified
syscall # System call is made


li $v0,5 # The integer print service is specified
syscall # System call is made

#move data to s0
move $s0,$v0

#if s0 less than or equal to zero exit
blez $s0,exit
#load 1 to s1 store the factorial
li $s1,1

loop:
mul $s1,$s1,$s0
sub $s0,$s0,1
bnez $s0,loop
la $a0,printmsg2 # Load the address of prompt
li $v0,4 # The string print service is specified
syscall # System call is made

#print result
move $a0,$s1
li $v0,1 # The string print service is specified
syscall # System call is made

j doAgain

exit:


Related Solutions

write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
Use MIPS write an assembly program which asks the user to enter 3 number. The program...
Use MIPS write an assembly program which asks the user to enter 3 number. The program then sorts these numbers, the prints them from largest to smallest.
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
Write a recursive function to calculate and return factorial of a given number 'n'. in C...
Write a recursive function to calculate and return factorial of a given number 'n'. in C progrmaining
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT