[prev] 35 [next]

Mapping Control Structures (cont)

Template for if...else if... else

if (Cond1) Stat1 else if (Cond2) Stat2 else Stat3

if:
   MIPS code to check Cond1; result in $t0
   beqz $t0, else1
   MIPS code for Stat1
   j    end_if
else1:
   MIPS code to check Cond2; result in $t0
   beqz $t0, else2
   MIPS code for Stat2
   j    end_if
else2:
   MIPS code for Stat3
end_if: