Cs 61C L3 Decisions.1 Patterson Spring 99 ©UCB CS61C Constants and Making Decisions in C/Assembly Language Lecture 3 January 27, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

Slides:



Advertisements
Similar presentations
CENG 311 Decisions in C/Assembly Language
Advertisements

Goal: Write Programs in Assembly
4.
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
cs61c L5 Decisions 9/13/00 1 CS61C - Machine Structures Lecture 5 - Decisions in C/Assembly Language September 13, 2000 David Patterson
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 6 – Introduction to MIPS Data Transfer & Decisions I Pieter Abbeel’s recent.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
COMP3221 lec13-decision-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 13: Making Decisions in C/Assembly Language - I
CS61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61CL L03 MIPS I: Registers, Memory, Decisions (1) Huddleston, Summer 2009 © UCB Jeremy Huddleston inst.eecs.berkeley.edu/~cs61c CS61CL : Machine Structures.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 – Introduction to MIPS Decisions II In what may be regarded as the most.
Cs 61C L2 Asm Ops.1 Patterson Spring 99 ©UCB CS61C C/Assembler Operators and Operands Lecture 2 January 22, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
CS61C L10 Introduction to MIPS : Decisions II (1) Garcia, Fall 2006 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L09 Introduction to MIPS: Data Transfer & Decisions I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS : Decisions II People are wondering what the next.
Lecture 4: Loads, Logic, Loops. Review Memory is byte-addressable, but lw and sw access one word at a time. These instructions transfer the contents of.
CS61C L7 MIPS Decisions (1) Garcia, Fall 2005 © UCB Lecturer PSOE, new dad Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
CS61C L10 Introduction to MIPS : Decisions II (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Decisions in C/Assembly Language Jen-Chang Liu, Spring 2006 Adapted from
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
CS61C L7 MIPS: Load & Store, Decisions (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
CS61C L7 MIPS Decisions (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #7 – MIPS.
CS 61C L07 MIPS Memory (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #7: MIPS Memory & Decisions.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
EEM 486 EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture.
CS1104 Assembly Language: Part 1
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 07 Introduction to MIPS : Decisions II Researchers at Microsoft and UW.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L10 Introduction to MIPS: Decisions II (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L10 Introduction to MIPS: Decisions II (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
More decisions and logic (1) Fall 2010 Lecture 4: Loads, Logic, Loops.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
Intel has developed a new technique to generate random numbers that is suitable for integration directly into the CPU! This circuit can turn out 2.4 billion.
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
IT 251 Computer Organization and Architecture More MIPS Control Instructions Chia-Chi Teng.
CHAPTER 6 Instruction Set Architecture 12/7/
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 07 Introduction to MIPS : Decisions II Guest Lecturer Alan Christopher.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Cs 61C L4 Functions.1 Patterson Spring 99 ©UCB CS61C Functions, Procedures in C/Assembly Language Lecture 4 January 29, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
Computer Organization Instructions Language of The Computer (MIPS) 2.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS: Load & Store, Decisions. Memory management review Three 3’s Picking blocks off free list  best-, first-, next-fit Attempts to solve external fragmentation.
CS2100 Computer Organisation
Computer Architecture & Operations I
Lecturer SOE Dan Garcia
The University of Adelaide, School of Computer Science
C second, objective-c, Go up!
Lecturer SOE Dan Garcia
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
March, 2006 Saeid Nooshabadi
Instruction Set Architecture
Presentation transcript:

cs 61C L3 Decisions.1 Patterson Spring 99 ©UCB CS61C Constants and Making Decisions in C/Assembly Language Lecture 3 January 27, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html

cs 61C L3 Decisions.2 Patterson Spring 99 ©UCB Review 1/2 °Big idea in CS&E; compilation to translate from one level of abstraction to lower level Generally single HLL statement produces many assembly instructions Also hides address calculations (byte vs. word addressing) °Design of an Assembly Language like MIPS shaped by 1) Desire to keep hardware simple: e.g., each operation has 3 operands 2) Smaller is faster: e.g., MIPS has 32 registers

cs 61C L3 Decisions.3 Patterson Spring 99 ©UCB Review 2/2 °MIPS assembly language thus far: Instructions: add, sub, lw, sw At most one assembly instruction per line Comments start with # to end of line Operands: registers $s0, $s1,... ; $t0, $t1,... Operands: memory Memory[0], Memory[4], Memory[8],,..., Memory[ ]

cs 61C L3 Decisions.4 Patterson Spring 99 ©UCB Overview °Constants (3 minutes) °C/Assembly if, goto, if-else (7 min) °C /Assembly Loops: goto, while (10 min) °Administrivia,“What’s this good for” (5) °Test for less (6 min) °C/Assembly case/switch statement (12) °C/Assembly for Example (6 minutes) °Conclusion (1 minute)

cs 61C L3 Decisions.5 Patterson Spring 99 ©UCB Assembly Constants °C expressions can have constants: i = i + 10; °How get them using instructions so far? Constants kept in memory with program lw $t0, 0($s0) # load 10 from memory add $s3,$s3,$t0 # i = i + 10 °So common, have instruction to add constants (called “immediate instructions”) addi $s3,$s3,10 # i = i + 10

cs 61C L3 Decisions.6 Patterson Spring 99 ©UCB Assembly Constants °Why include immediate instructions? Design principle: Make the common case fast Why faster? -Don’t need to access memory -2 instructions v. 1 instruction °Also,perhaps most popular constant is zero MIPS designers reserved 1 of 32 registers to always have the value 0; called “ $zero ” Useful in making additional operations from existing instructions; e.g., $s0  s1 add $s0, $s1, $zero # $s0 = $s1 + 0

cs 61C L3 Decisions.7 Patterson Spring 99 ©UCB C Decisions (Control Flow): if statements °2 kinds of if statements in C if ( condition ) statement if ( condition ) statement1 else statement2 °Following code is same as 2nd if if ( condition ) go to L1; statement2; go to L2; L1: statement1; L2: Not as elegant as if-else, but same meaning

cs 61C L3 Decisions.8 Patterson Spring 99 ©UCB MIPS decision instructions (control flow) °Decision instruction in MIPS: beq register1, register2, L1 beq is “Branch if (registers are) equal” Same meaning as (using C): if (register1==register2) go to L1 °Complementary MIPS decision instruction bne register1, register2, L1 bne is “Branch if (registers are) not equal” Same meaning as (using C): if (register1!=register2) go to L1 °Called conditional branches

cs 61C L3 Decisions.9 Patterson Spring 99 ©UCB Compiling C if into MIPS Assembly °Compile by hand if (i == j) f=g+h; else f=g-h; Mapping f : $s0, g : $s1, h : $s2, i : $s3, j : $s4 °Start with branch: beq $s3,s4, True # branch to True # if i==j °Follow with false part sub $s0,$s1,$s2# f=g-h(skip if i==j) Exit i == j? f=g+hf=g-h (false) i != j (true) i == j

cs 61C L3 Decisions.10 Patterson Spring 99 ©UCB Compiling C if into MIPS Assembly °Next must skip over true part Need instruction that always branches (unconditional branch) MIPS has jump: j Exit # go to Exit °Next is true part True: add $s0,$s1,$s2# f=g+h °Followed by exit branch label Exit:

cs 61C L3 Decisions.11 Patterson Spring 99 ©UCB Compiling C if into MIPS: Summary °Compile by hand if (i == j) f=g+h; else f=g-h; Mapping f : $s0, g : $s1, h : $s2, i : $s3, j : $s4 beq $s3,s4, True # branch i==j sub $s0,$s1,$s2 # f=g-h(false) j Exit # go to Exit True: add $s0,$s1,$s2 # f=g+h (true) Exit: ° Note:Compiler supplies labels, branches not found in HLL code; often it flips the condition to branch to false part i == j? f=g+hf=g-h (false) i != j (true) i == j C MIPSMIPS

cs 61C L3 Decisions.12 Patterson Spring 99 ©UCB Loops in C/Assembly °Simple loop in C Loop:g = g + A[i]; i = i + j; if (i != h) goto Loop; °1st fetch A[i] ( g, h, i, j :$s1,$s2,$s3,$s4;base of A[] :$s5): Loop: add $t1,$s3,$s3 #$t1= 2*i add $t1,$t1,$t1 #$t1= 4*i add $t1,$t1,$s5 #$t1=addr A lw $t1,0($t1) #$t1=A[i]

cs 61C L3 Decisions.13 Patterson Spring 99 ©UCB Loops in C /Assembly °Add A[i] to g and then j to i ( g, h, i, j :$s1,$s2,$s3,$s4): add $s1,$s1,$t1# g = g+A[i] add $s3,$s3,$s4# i = i + j The final instruction branches back to Loop if i != h : bne $s3,$s2,Loop # goto Loop # if i!=h

cs 61C L3 Decisions.14 Patterson Spring 99 ©UCB Loops in C/Assembly: Summary Loop:g = g + A[i]; i = i + j; if (i != h) goto Loop; ( g, h, i, j :$s1,$s2,$s3,$s4 : base of A[] :$s5) Loop: add $t1,$s3,$s3 #$t1= 2*i add $t1,$t1,$t1 #$t1= 4*i add $t1,$t1,$s5 #$t1=addr A lw $t1,0($t1) #$t1=A[i] add $s1,$s1,$t1 #g=g+A[i] add $s3,$s3,$s4 #i=i + j bne $s3,$s2,Loop# goto Loop # if i!=h C MIPSMIPS

cs 61C L3 Decisions.15 Patterson Spring 99 ©UCB While in C/Assembly: °Although legal C, almost never write loops with if, goto : use while, for loops °Syntax: while (condition) statement while (save[i]==k) i = i + j; °1st load save[i] into a temporary register ( i, j, k : $s3,$s4,$s5: base of save[] :$s6): Loop: add $t0,$s3,$s3#$t0 = 2*i add $t0,$t0,$t0#$t0 = 4*i add $t0,$t0,$s6#$t0=Addr lw $t1,0($t0) #$t1=save[i]

cs 61C L3 Decisions.16 Patterson Spring 99 ©UCB While in C/Assembly: °Loop test, exiting if save[i] != k ( i, j, k : $s3,$s4,$s5: base of save[] :$s6): bne $t1,$s5,Exit#goto Exit #if save[i]!=k °The next instruction adds j to i: add $s3,$s3,$s4# i = i + j °End of loop branches back to the while test at top of loop. Add the Exit label after: j Loop# goto Loop Exit:

cs 61C L3 Decisions.17 Patterson Spring 99 ©UCB While in C/Assembly: Summary while (save[i]==k) i = i + j; ( i, j, k : $s3,$s4,$s5: base of save[] :$s6) Loop: add $t0,$s3,$s3 #$t0 = 2*i add $t0,$t0,$t0 #$t0 = 4*i add $t0,$t0,$s6 #$t0=Addr lw $t1,0($t0) #$t1=save[i] bne $t1,$s5,Exit#goto Exit #if save[i]!=k add $s3,$s3,$s4# i = i + j j Loop# goto Loop Exit: C MIPSMIPS

cs 61C L3 Decisions.18 Patterson Spring 99 ©UCB Administrivia °Change in what said last time: teams of 1-2, not 3 Much less chance of being “third wheel” if team size is 2; OK to do by yourself 1-2 people for Labs, Exercises, Projects May change and work with different people °Read COD 3.6, Appendix A.6 °1st homework: Due today (1/27) 7PM (grace period until 8AM tomorrow) °1st project: C spelling checker philspel Due Wed. 2/3 7PM (do by yourself) www-inst.EECS/~cs61c/handouts/proj1.pdf

cs 61C L3 Decisions.19 Patterson Spring 99 ©UCB Administrivia °2nd homework: Due Wed 2/3 7PM Exercises 3.1, 3.2, 3.4, 3.6, 3.9 Which instruction set inside? Search WWW  Apple iMAC  Casio PalmPC  Cisco Network Routers  HP LaserJet 4000  IBM PC  Kodak DC260 Digital Camera  Discussion section moved: Th 4-5 to 247 Cory  NASA Mars Rover  Nintendo 64  Sony Playstation  Web TV set top box

cs 61C L3 Decisions.20 Patterson Spring 99 ©UCB Administrivia °Classroom Decorum If need to leave before end of class, sit at end of row near door? Disrupting attention of your classmates °“And in Conclusion …” Thus far it has been as sign to start shuffling papers : too much noise to hear? As it is only 1 minute before end of class, please wait for 60 seconds before making noise? °New option on lecture notes: 4/page in pdf format; fast to download and print at home

cs 61C L3 Decisions.21 Patterson Spring 99 ©UCB “What’s This Stuff Good For?” Breathing Observation Bubble: BOB pipes air from a tank under the handlebars into an acrylic dome, replacing a diver's face mask and breathing apparatus. Wireless technology lets riders talk to other BOBsters darting through the water nearby, as well as to armchair divers above in a boat or back on shore. Saving energy from not having to kick, divers can stay submerged almost an hour with the BOB. Like most modern scuba gear, the BOB features a computer that tells riders when to come up and calculates decompression times for a safe return to the surface. One Digital Day, What do applications (“apps”) like these mean for reliability requirements of our technology?

cs 61C L3 Decisions.22 Patterson Spring 99 ©UCB Beyond equality tests in MIPS Assembly °So far ==, !=, What about ? °MIPS instruction “Set Less Than” slt register1,register2,register3 °Meaning of slt in C if (register2 < register 3) register1 = 1; else register1 = 0; °Branches then test result in register 1 °Try if (g < h) go to Less

cs 61C L3 Decisions.23 Patterson Spring 99 ©UCB If less in C/Assembly if (g < h) go to Less slt $t0,$s0,$s1 # $t0 = 1 if # $s0<$s1 (g<h) bne $t0,$zero, Less # goto Less # if $t0!=0... #(if (g <h)) Less: A branch if $t0 != 0 branches if g < h. Register $zero always 0, so use bne comparing register $t0 to register $zero °How test if (g >= h)? C MIPSMIPS

cs 61C L3 Decisions.24 Patterson Spring 99 ©UCB Set Less Than Immediate in C/Assembly °Also immediate version of slt to test against constants: slti Helpful in for loops if (g >= 1) go to Loop Loop:... slti $t0,$s0,1 # $t0 = 1 if # $s0 =1)) C MIPSMIPS

cs 61C L3 Decisions.25 Patterson Spring 99 ©UCB C case/switch statement °Choose among four alternatives depending on whether k has the value 0, 1, 2, or 3 switch (k) { case 0: f=i+j; break; /* k=0*/ case 1: f=g+h; break; /* k=1*/ case 2: f=g–h; break; /* k=2*/ case 3: f=i–j; break; /* k=3*/ }

cs 61C L3 Decisions.26 Patterson Spring 99 ©UCB Case/switch via chained if-else, C/Asm. °Could be done like chain of if-else if(k==0) f=i+j; else if(k==1) f=g+h; else if(k==2) f=g–h; else if(k==3) f=i–j; bne $s5,$zero, L1 # branch k!=0 add $s0,$s3,$s4 #k=0 so f=i+j j Exit # end of case so Exit L1:subi $t1,$s5,1# $t0=k-1 bne $t1,$zero,L2 # branch k!=1 add $s0,$s1,$s2 #k=1 so f=g+h j Exit # end of case so Exit L2:subi $t1,$s5,2# $t0=k-2 bne $t1,$zero,L3 # branch k!=2 sub $s0,$s1,$s2 #k=2 so f=g-h j Exit # end of case so Exit L3:sub $s0,$s3,$s4 #k=3 so f=i-j Exit: C MIPSMIPS

cs 61C L3 Decisions.27 Patterson Spring 99 ©UCB Case/Switch via Jump Address Table °Notice that last case must wait for n-1 tests before executing, making it slow °Alternative tries to go to all cases equally fast: jump address table Idea: encode alternatives as a table of addresses of the cases -Table an array of words with addresses corresponding to case labels Program indexes into table and jumps °MIPS instruction “jump register” ( jr ) unconditionally branches to address in register; use load to get address

cs 61C L3 Decisions.28 Patterson Spring 99 ©UCB Case/Switch via Jump Address Table 1/3 °Use k to index a jump address table, and then jump via the value loaded °1st test that k matches 1 of cases (0 =4,goto Exit °Multiply k by 4 to index table of words: add $t1,$s5,$s5# Temp reg $t1 = 2*k add $t1,$t1,$t1# Temp reg $t1 = 4*k

cs 61C L3 Decisions.29 Patterson Spring 99 ©UCB Case/Switch via Jump Address Table 2/3 °Assume 4 sequential words in memory, base address in $t2, have addresses corresponding to labels L0, L1, L2, L3. add $t1,$t1,$t2# $t1=addr JumpTable[k] lw $t1,0($t1)# $t1 = JumpTable[k] °Now jump using address in register $t1: jr $t1# jump based on reg. $t1

cs 61C L3 Decisions.30 Patterson Spring 99 ©UCB Case/Switch via Jump Address Table 3/3 °Cases jumped to by jr : L0:add $s0,$s3,$s4# k=0 so f = i + j j Exit# end case, goto Exit L1:add $s0,$s1,$s2# k=1 so f = g + h j Exit# end case, goto Exit L2:sub $s0,$s1,$s2# k=2 so f = g – h j Exit# end case, goto Exit L3:sub $s0,$s3,$s4# k=3 so f = i – j Exit:# end of switch statement

cs 61C L3 Decisions.31 Patterson Spring 99 ©UCB Jump Address Table: Summary slti $t3,$s5,0 #Test if k =4,goto Exit add $t1,$s5,$s5# Temp reg $t1 = 2*k add $t1,$t1,$t1# Temp reg $t1 = 4*k add $t1,$t1,$t2# $t1=addr JumpTable[k] lw $t1,0($t1)# $t1 = JumpTable[k] jr $t1 # jump based on $t1 L0:add $s0,$s3,$s4# k=0 so f = i + j j Exit# end case, goto Exit L1:add $s0,$s1,$s2# k=1 so f = g + h j Exit# end case, goto Exit L2:sub $s0,$s1,$s2# k=2 so f = g – h j Exit# end case, goto Exit L3:sub $s0,$s3,$s4# k=3 so f = i – j Exit:# end of switch statement

cs 61C L3 Decisions.32 Patterson Spring 99 ©UCB If there is time, do it yourself: °Compile this MIPS code: sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum : $s3, i : $s4, base address of A : $s5

cs 61C L3 Decisions.33 Patterson Spring 99 ©UCB (If time allows) Do it yourself: sum = 0; for (i=0;i<10;i=i+1) sum = sum + A[i]; sum : $s3, i : $s4, base address of A : $s5 add $s3,$zero,$zero# sum = 0 add $s4,$zero,$zero # i = 0 j Test # test before Loop: add $t1,$s4,$s4# $t1 = 2*i add $t1,$t1,$t1 # $t1 = 4*i add $t1,$t1,$s5 #$t1=addr Ai lw $t0,0($t1) #$t0 = A[i] add $s3,$s3,$t0 #sum+= A[i] Test: slti $t0,$s4,10 # $t0=(i<10) bne $t0,$zero,Loop # goto Less C MIPSMIPS

cs 61C L3 Decisions.34 Patterson Spring 99 ©UCB “And in Conclusion …” 1/1 °Constants so common have special version of arithmetic, registers addi, subi; register $zero (always 0) Principle: Making common case fast °HLL decisions (if, case) and loops (while, for) use same assembly instructions Conditional branches: beq, bne in MIPS Unconditional branches: j, jr in MIPS Relative test: slt, slti in MIPS Case/Switch: either jump table + jr or simply chained if-else Next: procedures, functions