Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
Advertisements

Lecture 5: MIPS Instruction Set
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
ELEN 468 Advanced Logic Design
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
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.
MIPS Instruction Set Advantages
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
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.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MS108 Computer System I Lecture 3 ISA Prof. Xiaoyao Liang 2015/3/13 1.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Jump and Branch Instructions
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture & Operations I
MIPS Assembly.
MIPS Instruction Set Advantages
CSCI206 - Computer Organization & Programming
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
Computer Architecture & Operations I
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Design of the Control Unit for Single-Cycle Instruction Execution
Computer Organization and Design Instruction Sets
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
MIPS coding.
Lecture 4: MIPS Instruction Set
CSCI206 - Computer Organization & Programming
ARM Control Structures
Design of the Control Unit for One-cycle Instruction Execution
Computer Architecture & Operations I
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
CSCI206 - Computer Organization & Programming
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
Flow of Control -- Conditional branch instructions
3.
COMS 361 Computer Organization
COMS 361 Computer Organization
ARM Control Structures
MIPS Assembly.
Flow of Control -- Conditional branch instructions
MIPS e pipelining Tecniche di base.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
Branch & Call Chapter 4 Sepehr Naimi
7/6/
9/13/
MIPS instructions.
Conditional Branching (beq)
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement, sometimes combined with “go to” statements and “labels”. MIPS assembly language includes many decision-making instructions. Two of them are BEQ and BNE.

Branch on Equal if ($u == $v) then jump to “Label” beq u,v,Label if the bit patterns in register $u == register $v PC <-- address of Label after a delay of one machine cycle. else Continue the sequence of instructions without jumping. bit patterns – unsigned or two’s complement ?

“If” structure IF $8 equals to $9 then go to CONT. Otherwise do the block of statements Then again go through the CONT

“If” structure on assembly The bit patterns in two registers are compared. If the bit patterns are the same, the PC is changed to the branch address. There is a branch delay following the instruction (just as for a jump instruction). ... # load values into $8 and $9 beq $8,$9,cont # branch if equal sll $0,$0,0 # branch delay slot ... # conditionally ... # executed ... # statements cont: add $10,$10,$11 # always executed

? Two – way decision ... # load values into # $8 and $9 beq $8,$9,equal # branch if equal sll $0,$0,0 # branch delay slot ... # ... # false branch j cont equal: ... # ... # true branch cont: add $10,$10,$11 # always executed ?

Branch on Not Equal if ($u != $v) then jump to “Label” bne u, v, Label if register $u != register $v PC <-- address of Label after a delay of one machine cycle. else Continue the sequence of instructions without jumping.

Absolute Value calculation # Get A lui $10,0x1000 # base register lw $8,0($10) # Load A sll $0,$0,0 # no-op # Is A Negative? srl $9,$8,31 # Shift sign bit beq $0,$9,done # sign bit == zero # Store –A sub $8,$0,$8 # negate A sw $8,0($10) # save it done: sll $0,$0,0 # target of the branch .data A: .word -1

BEQ instruction format beq $0, $9, done beq $0 $9 0 0 0 3 opcode oprnd dest offset(2’s comp.) 000100 00000 01001 0000 0000 0000 0011 0001 0000 0000 1001 0000 0000 0000 0011 1 0 0 9 0 0 0 3 New PC = PC + Off*4 = 0x00400010+4 + 0x0003*4 = 0x00400014 + 0x0000000C = 0x00400020 [0x00400000] 0x3c0a1000 lui $10, 4096 [0x00400004] 0x8d480000 lw $8, 0($10) [0x00400008] 0x00000000 nop [0x0040000c] 0x00084fc2 srl $9, $8, 31 PC+4 [0x00400010] 0x10090003 beq $0,$9,12 [done-0x00400010] [0x00400014] 0x00000000 nop +12 [0x00400018] 0x00084022 sub $8, $0, $8 [0x0040001c] 0xad480000 sw $8, 0($10) done:[0x00400020] 0x00000000 nop

Addressing Modes 4. BEQ and BNE use PC-relative addressing, where the branch address is the sum of the PC and a constant in the instruction Addressing mode – One of several addressing regimes delimited by their varied use of operands and or addresses.