3
* 2 Review (1/2) ° In MIPS Assembly Language: Registers replace C variables One Instruction (simple operation) per line Simpler is Better Smaller is Faster ° Memory is byte-addressable, but lw and sw access one word at a time. ° A pointer (used by lw and sw ) is just a memory address, so we can add to it or subtract from it (using offset).

8
* 7 MIPS Goto Instruction ° In addition to conditional branches, MIPS has an unconditional branch: jlabel ° Called a Jump Instruction: jump (or branch) directly to the given label without needing to satisfy any condition ° Same meaning as (using C): goto label ° Technically, it’s the same as: beq $0,$0,label since it always satisfies the condition.

15
* 14 Loops in C/Assembly (3/3) ° There are three types of loops in C: while do … while for ° Each can be rewritten as either of the other two, so the method used in the previous example can be applied to while and for loops as well. ° Key Concept: Though there are multiple ways of writing a loop in MIPS, conditional branch is key to decision making

20
* 19 Inequalities in MIPS (4/4) ° Now, we can implement, = ? ° We could add 3 more instructions, but: MIPS goal: Simpler is Better ° Can we implement <= in one or more instructions using just slt and the branches? ° What about >? ° What about >=?

21
* 20 Immediates in Inequalities ° There is also an immediate version of slt to test against constants: slti Helpful in for loops if (g >= 1) goto Loop C MIPSMIPS

22
* 21 Immediates in Inequalities ° There is also an immediate version of slt to test against constants: slti Helpful in for loops if (g >= 1) goto Loop Loop:... slti $t0,$s0,1 # $t0 = 1 if # $s0 =1)) C MIPSMIPS

28
* 27 Things to Remember (1/2) ° A Decision allows us to decide which pieces of code to execute at run-time rather than at compile-time. ° C Decisions are made using conditional statements within an if, while, do while or for. ° MIPS Decision making instructions are the conditional branches: beq and bne. ° In order to help the conditional branches make decisions concerning inequalities, we introduce a single instruction: “Set on Less Than”called slt, slti, sltu, sltui