Question: Translate the following C code to MIPS assembly code. Initialize the variable factorial to 1, and calculate the factorial of 5 using a for loop.
Translate the following C code to MIPS assembly code. Initialize the variable factorial to 1, and calculate the factorial of 5 using a for loop. The result should be stored in the variable factorial. Assume that the value of factorial is stored in register $s0. If needed, you may use mul instruction. For example, mul $t0, $t0, $t1 performs a multiplication operation between the contents registers $t0 and $t1, and stores the result in register $t0.
C Code:
int factorial = 1;
for (int i = 1; i <= 5; i++) {
factorial *= i;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
