Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the following C code into MIPS assmble code, the code is about drawing triangles using asterisk. Check the output of the c code first.

Convert the following C code into MIPS assmble code, the code is about drawing triangles using asterisk. Check the output of the c code first. : #include
void print_layer(int n, int l){
for (int j =1; j < n-l; j++){
printf("");
}
for (int j = n-l; j <= n+l; j++){
printf("*");
}
printf("
");
}
int main(){
int op;
printf("Please enter option (1: triangle, 2: inverted triangle): ");
scanf("%d", &op);
int n;
printf("Please input a triangle size: ");
scanf("%d", &n);
for (int i =0; i < n; i++){
if (op ==1){
print_layer(n, i);
} else {
print_layer(n, n-i-1);
}
}
return 0;
}
check the code output using the following test.h script, run it on ubuntu. Add your own test cases.
#!/bin/bash
TESTCASE_ROOT="./testcase"
TESTCASE_ANSWER_ROOT="./testcase_answer"
STUDENT_ANSWER_ROOT="./student_answer"
problems=(
"factorial"
"prime"
"calculator"
"triangle"
"fibonacci"
)
test_problem(){
local prolbem=$1
local source_c_file="./${problem}.c"
local source_asm_file="./${problem}.s"
local executable_file="./$problem"
echo "Testing Problem: $problem"
if [!-f "$source_c_file" ]; then
echo "Source c file not found: $source_c_file"
return
fi
if [!-f "$source_asm_file" ]; then
echo "Source asm file not found: $source_asm_file"
return
fi
gcc "$source_c_file" -o "$executable_file"
testcase_files=($(ls $TESTCASE_ROOT | grep $problem))
for file in "${testcase_files[@]}"; do
local testcase_path="$TESTCASE_ROOT/$file"
local testcase_answer_path="$TESTCASE_ANSWER_ROOT/$file"
local student_answer_path="$STUDENT_ANSWER_ROOT/$file"
"$executable_file" <"$testcase_path" >"$testcase_answer_path"
spim -file "$source_asm_file" <"$testcase_path" | tail -n $(awk 'END {print NR}' $testcase_answer_path)>"$student_answer_path"
diff_output=$(diff $testcase_answer_path $student_answer_path)
if [-z "$diff_output" ]; then
echo "$file PASS"
else
echo "$file FAIL"
echo "$diff_output"
fi
done
rm "$executable_file"
}
mkdir -p "$TESTCASE_ANSWER_ROOT"
mkdir -p "$STUDENT_ANSWER_ROOT"
for problem in "${problems[@]}"; do
test_problem "$problem"
echo "------------------------------------"
done
screenshot the output, make sure the code works.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

Students also viewed these Databases questions

Question

Distinguish between verification and valuation.

Answered: 1 week ago

Question

Solve the following 1,4 3 2TT 5x- 1+ (15 x) dx 5X

Answered: 1 week ago

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

Assess three motivational theories as they apply to health care.

Answered: 1 week ago

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago