Rendering C in MIPS: Iteration (Loops)
Iteration (e.g. while and for )
Again we can map our C program to simplified C using goto statements and then map it to MIPS
top_while:
while (Cond) { if(! Cond)
Statements; goto end_while:
} execute Statements
goto top_while
end_while:
|
Treat for as a special case of while
i = 0
for (i = 0; i < N; i++) { while (i < N) {
Statements; Statements;
} i++;
}
|
|