# L10 - CS61C Machine Structures Lecture 10 - MIPS Branch...

This preview shows pages 1–5. Sign up to view the full content.

CS 61C L10 MIPS Branch II (1) Wawrzynek Fall 2007 © UCB 9/19/2006 Greg Gibeling (for John Wawrzynek) (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS61C – Machine Structures Lecture 10 - MIPS Branch Instructions II CS 61C L10 MIPS Branch II (2) Wawrzynek Fall 2007 © UCB Compiling C if into MIPS (1/2) ° Compile by hand if (i == j) f=g+h; else f=g-h; ° Use this mapping: f : \$s0 g : \$s1 h : \$s2 i : \$s3 j : \$s4 Exit i == j? f=g+h f=g-h (false) i != j (true) i == j

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

View Full Document
CS 61C L10 MIPS Branch II (3) Wawrzynek Fall 2007 © UCB Compiling C if into MIPS (2/2) ° Final compiled MIPS code: beq \$s3,\$s4,True # branch i==j sub \$s0,\$s1,\$s2 # f=g-h(false) j Fin # goto Fin True: add \$s0,\$s1,\$s2 # f=g+h (true) Fin: Note: Compiler automatically creates labels to handle decisions (branches). Generally not found in HLL code. Exit i == j? f=g+h f=g-h (false) i != j (true) i == j Compile by hand if (i == j) f=g+h; else f=g-h; CS 61C L10 MIPS Branch II (4) Wawrzynek Fall 2007 © UCB Review ° 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). ° A Decision allows us to decide what to execute at run-time rather than compile-time. ° C Decisions are made using conditional statements within if , while , do while , for . ° MIPS Decision making instructions are the conditional branches : beq and bne . ° New Instructions: lw, sw, beq, bne, j

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

View Full Document
CS 61C L10 MIPS Branch II (7) Wawrzynek Fall 2007 © UCB
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/09/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

### Page1 / 12

L10 - CS61C Machine Structures Lecture 10 - MIPS Branch...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online