Question: Convert the following C program into MIPS assambly code, the code is about a simple calculator. Fist ask for user input, option 1 is for
Convert the following C program into MIPS assambly code, the code is about a simple calculator. Fist ask for user input, option is for addition, option is for subtraction option is for multiplication. Here's the C code:
#include
int main
int op;
printfPlease enter option : add, : sub, : mul: ;
scanfd &op;
int a b;
printfPlease enter the first number: ;
scanfd &a;
printfPlease enter the second number: ;
scanfd &b;
int ans;
if op
ans a b;
else if op
ans a b;
else if op
ans a b;
printfThe calculation result is: d
ans;
return ;
test your code to see if the output is the similar to the c code given using MIPS simulator and using this test.h 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
