Question
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
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
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