MIPS2 - Control flow in high-level languages The...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
24 The instructions in a program usually execute one after another, but it’s often necessary to alter the normal control flow. Conditional statements execute only if some test expression is true. // Find the absolute value of *a0 v0 = *a0; if (v0 < 0) v0 = -v0; // This might not be executed v1 = v0 + v0; Loops cause some statements to be executed many times. // Sum the elements of a five-element array a0 v0 = 0; t0 = 0; while (t0 < 5) { v0 = v0 + a0[t0]; // These statements will t0++; // be executed five times } Control flow in high-level languages
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
25 In this lecture, we introduced some of MIPS’s control-flow instructions j immediate // for unconditional jumps jr $r1 // jump to address stored in $r1 bne and beq $r1, $r2, label // for conditional branches slt and slti $rd, $rs, $rt // set if less than (w/ and w/o an immediate) $rs, $rt, imm And how to implement loops Today, we’ll talk about MIPS’s pseudo branches if/else case/switch MIPS control instructions
Image of page 2