Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C to MIPS: How would I go about converting the following if-else statement? I know how to do simpler ones, but this one is more

C to MIPS: How would I go about converting the following if-else statement? I know how to do simpler ones, but this one is more complex. Full C code of nested for loop and if-else below, assembly (nested loops) I have so far also included.

C:

for(i=0; i= y1 && i <= y2 && j >= x1 && j <= x2){ printf("%d %d %d ", r, g, b); //if row/column is inside box, print original rgb values }else{

printf("%d %d %d ", gray, gray, gray);//if row/column is outside box, print gray values } } }

MIPS:

loop1: bge $s0, $t1, end # for (i = 0; i < rows; i++) addi $s0, $s0, 1 # i++ li $t9, 0 # resets j to 0 j loop2 # execute inside loop loop2: bge $t9, $t0, loop1 # for (j = 0; j < columns; j++)

li $v0, 5 # reads red (integer) from the user syscall add $a0, $v0, $0 # stores red in $a0 li $v0, 5 # reads green (integer) from the user syscall add $a1, $v0, $0 # stores green in $a1 li $v0, 5 # reads blue (integer) from the user syscall add $a2, $v0, $0 # stores blue in $a2

jal rgb_to_gray #procedure to calculate gray value #insert if else statement here? addi $v0, $0, 1 # call to print grayscale value (1st time) add $a0, $0, $t3 # store value returned from rgb_to_gray in $a0 syscall addi $v0, $0, 4 # prepare to print new line la, $a0, newline # print new line addi $v0, $0, 1 # call to print grayscale value (2nd time) add $a0, $0, $t3 # store value returned from rgb_to_gray in $a0 syscall addi $v0, $0, 4 # prepare to print new line la, $a0, newline # print new line addi $v0, $0, 1 # call to print grayscale value (3rd time) add $a0, $0, $t3 # store value returned from rgb_to_gray in $a0 syscall

addi $v0, $0, 4 # prepare to print new line la, $a0, newline # print new line syscall addi $t9, $t9, 1 # increment j by 1 j loop2

end: ori $v0, $0, 10 # system call 10 for exit syscall # exit

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_2

Step: 3

blur-text-image_3

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

=+How does this metric connect to my objectives?

Answered: 1 week ago

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago