Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Convert the following C code into MIPS Assembly code, the program is about fibonacci seqeuence. Here's the code: #include int fibonacci ( int n )
Convert the following C code into MIPS Assembly code, the program is about fibonacci seqeuence. Here's the code:
#include
int fibonacciint n
if n
return ;
else if n
return ;
else
return fibonaccin fibonaccin;
int main
int n;
printfPlease input a number: ;
scanfd &n;
printfThe result of fibonaccin is d
fibonaccin;
return ;
Check the code results with the following test.h script, to see whether the output is similar to that of the C code, here's the script:
#binbash
TESTCASEROOTtestcase
TESTCASEANSWERROOTtestcaseanswer"
STUDENTANSWERROOTstudentanswer"
problems
"factorial"
"prime"
"calculator"
"triangle"
"fibonacci"
testproblem
local prolbem$
local sourcecfile$problemc
local sourceasmfile$problems
local executablefile$problem"
echo "Testing Problem: $problem"
if f $sourcecfile" ; then
echo "Source c file not found: $sourcecfile"
return
fi
if f $sourceasmfile" ; then
echo "Source asm file not found: $sourceasmfile"
return
fi
gcc $sourcecfile" o $executablefile"
testcasefiles$ls $TESTCASEROOT grep $problem
for file in $testcasefiles@; do
local testcasepath$TESTCASEROOT$file"
local testcaseanswerpath$TESTCASEANSWERROOT$file"
local studentanswerpath$STUDENTANSWERROOT$file"
$executablefile" $testcasepath" $testcaseanswerpath"
spim file $sourceasmfile" $testcasepath" tail n $awk 'END print NR $testcaseanswerpath$studentanswerpath"
diffoutput$diff $testcaseanswerpath $studentanswerpath
if z $diffoutput" ; then
echo $file PASS"
else
echo $file FAIL"
echo $diffoutput"
fi
done
rm $executablefile"
mkdir p $TESTCASEANSWERROOT"
mkdir p $STUDENTANSWERROOT"
for problem in $problems@; do
testproblem $problem"
echo
done
You can create your own test cases. Please run it on Ubuntu linux test the code using MIPS simulator.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started