17 - Jumps & Branches. The PC PC marks next location in Fetch, Decode, Execute cycle.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CENG 311 Decisions in C/Assembly Language
4.
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Lecture 5: MIPS Instruction Set
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.
Branches Two branch instructions:
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Comp Sci Control structures 1 Ch. 5 Control Structures.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Assembly Language (cont)
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Lecture 8: MIPS Instruction Set
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Lecture 3a: Supplemental Notes for Chapter 3 CS 447 Jason Bakos.
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.
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.
More decisions and logic (1) Fall 2010 Lecture 4: Loads, Logic, Loops.
MIPS Instruction Set Advantages
Automobile Manufacturing 1. Build frame. 60 min. 2. Add engine. 50 min. 3. Build body. 80 min. 4. Paint. 40 min. 5. Finish.45 min. 275 min. Latency: Time.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
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.
IT 251 Computer Organization and Architecture More MIPS Control Instructions Chia-Chi Teng.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Lecture 4: MIPS Instruction Set
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.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
Jump and Branch Instructions
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Single Cycle CPU - Control
Computer Architecture & Operations I
CSCI206 - Computer Organization & Programming
MIPS Instruction Set Advantages
ECE 3430 – Intro to Microcomputer Systems
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
Decision Making.
More Branch Instructions and Set Instructions
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Instructions for Making Decisions
The University of Adelaide, School of Computer Science
Pick up the handout on your way in!!
Week 6 The darkness, the loop of negative thoughts on repeat, clamours and interferes with the music I hear in my head. Lady Gaga.
Single-Cycle CPU DataPath.
Control Flow and Arrays
CSCI206 - Computer Organization & Programming
ARM Control Structures
How to represent signed integers
ECE232: Hardware Organization and Design
MIPS coding.
The University of Adelaide, School of Computer Science
October 24 Programming problems? Read Section 6.1 for November 5
Flow of Control -- Conditional branch instructions
A 1-Bit Arithmetic Logic Unit
ARM Control Structures
Flow of Control -- Conditional branch instructions
MIPS assembly.
CSE 410, Spring 2008 Computer Systems
MIPS instructions.
Conditional Branching (beq)
Control Flow and Arrays
Presentation transcript:

17 - Jumps & Branches

The PC PC marks next location in Fetch, Decode, Execute cycle

Jumps PC not directly addressable – Modified by instructions j : Unconditional jump to label

Using J Label converted to address by assembler:

J Type J : Jump instruction – 26 bit location

J Type J : Jump instruction – 26 bits devoted to address of label

J Type 26 bit location  32 bit address – Shift left 2 Word addresses only – Steal left 4 bits from PC Direct jump only to same region of memory Region1111 Region… … … … … … … … 0110 Region0101 Region0100 Region0011 Region0010 Region0001 Region0000

Decoding J Jump Instruction: 0x code address Shift: Copy first 4 bits of current address: (0x c) x – effective address to jump to

Delayed Branch MIPS delay's branches – One extra op happens after branch/jump – Must enable in MARS settings

Delayed Branch One extra instruction always happens after jump – Shown in green in simulator

NOP NOP : no –op – Prevent unwanted work after branch

BEQ & BNE BEQ : Branch Equal BNE : Branch Not Equal beq $reg1, $reg2, label Compare 2 registers, possibly branch – Branch relative to current instruction – Range +/- ~2 19 instructions

If Assembly if’s are “backwards” High LevelAssembly if(i == j) { k = 1; } … Branch to cont if $i != $j $k = 1 cont: ….

If If implemented with branch: – Skip ahead if NOT doing if body

If / Else If/Else implemented with branch: – Branch to skip if body for else case – If body jumps to skip else body High LevelAssembly if(i == j) { k = 1; } else { k = 2; } … Branch to else if $i != $j $k = 1 jump to endif else: $k = 2 endif: …

If/Else implemented with branch: – Branch to skip if body for else case – If body jumps to skip else body If / Else

ASM ABS Absolute value of A from memory

18 – Inequalities & Conditional Sets

Other Branches / Sets Single register branches – bltz : register less than zero – blez : register less than or equal to zero – bgtz : register greater than zero – bgez : register greater than or equal to zero

2 Register BLT is Cheating Two register inequalities are psuedo-ops – Don't use this week

If / Else Inequalities in assembly – Rewrite solved for 0 – Invert for skip logic High LevelAssembly if(i < j) { k = 1; } … Calculate $i - $j Branch to endif if >= 0 $k = 1 endif: …

If < If (i < j) k = 10;

Real If Real C++Real compiler output: What is slt???

Set Set : changes a register 1 or 0 depending on condition of test – slt $a, $b, $c set $A if $B < $C – sltu $a, $b, $c set $A if $B < $C compare as unsigned values – slti $a, $b, value set $A if $B <= immediate – sltiu $a, $b, value set $A if $B <= immediate compare as unsigned

If compiler style If (i < j) k = 10; //using slt

Temp Check Set bit if 30 <= temp <= 55

Loop = jump backwards int i = 0; while(i < 10) { //do stuff i++; }

Counting Loop While(i < 10)

Sum Sum 0…9

Real Code Counting Loop Compilers often move test to end of loop: – Avoid separate test and jump for all iterations > 1