Given the general construct of if..else in C as
if(cond) {
block_if};
else {
block_else};
what will be the corresponding structure of if_else in MIPS?
Given the general construct of if..else in C as
if(cond) {
block_if};
else {
block_else};
what will be the corresponding structure of if_else in MIPS?
Here's an if-else control structure in MIPS.
It's just a branch instruction to jump to the else
label if the condition is false. Otherwise, it continues, executes the if's body, and then jumps to the end
label.
After that jump instruction is the else
label, followed by the else's body, and then the end
label.
The code in the if's body executes only if the condition is true, and the code in the else's body only executes if the condition is false.
# $t0 = cond
beq $t0,$zero,else
# if(cond) {
# Do code
j end
# } else {
else:
# Do code
# }
end: