CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 10/15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.

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
Goal: Write Programs in Assembly
4.
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.
Lecture 20: 11/12/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
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.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
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.
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
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.
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
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.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /22/2013 Lecture 12: Character Data Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
CDA 3101 Spring 2016 Introduction to Computer Organization
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.
Ch2a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Taking orders A computer does what you tell it to do Not necessarily what.
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
Computer Architecture Instruction Set Architecture
MIPS Instruction Set Advantages
CS2100 Computer Organisation
The University of Adelaide, School of Computer Science
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
Decision Making.
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
Instructions for Making Decisions
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
MIPS coding.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
ECE232: Hardware Organization and Design
Lecture 5: Procedure Calls
MIPS coding.
Chapter 2 Instructions: Language of the Computer part 2
The University of Adelaide, School of Computer Science
3.
COMS 361 Computer Organization
MIPS Assembly.
MIPS Coding Continued.
MIPS coding.
MIPS assembly.
Computer Architecture
MIPS instructions.
Conditional Branching (beq)
Presentation transcript:

CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE UNIVERSITY, WILBERFORCE, OH 1

Review  Last Class  Binary Integers Unsigned, Signed, Signed Extension  Representation of MIPS Instructions R-format I-format  This Class  Conditional Instructions slt  Branch Addressing  Next Class  Procedure 2

Instructions for Making Decisions  High-level programming language C/C++: if … else … (conditional) goto(unconditional) for, while, until (loops)  Assembly Languages MIPS: beq (branch if equal) bne (branch if not equal) j(unconditional jump) 3

Conditional Operations  Branch to a labeled instruction if a condition is true  Otherwise, continue sequentially  beq rs, rt, L1  if (rs == rt) branch to instruction labeled L1;  bne rs, rt, L1  if (rs != rt) branch to instruction labeled L1;  j L1  unconditional jump to instruction labeled L1 4

Compiling If Statements  C code: if (i==j) f = g+h; else f = g-h; 5

Compiling If Statements  C code: if (i==j) f = g+h; else f = g-h;  f ($s0), g ($s1), h($s2), i($s3), j($s4)  Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit: … Assembler calculates addresses 6

Compiling Loop Statements  C code: while (save[i] == k) i = i+1;  i in $s3, k in $s5, address of save in $s6  Flowchart? 7

Compiling Loop Statements  C code: while (save[i] == k) i = i+1;  i in $s3, k in $s5, address of save in $s6  Compiled MIPS code: Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: … 8

Basic Blocks  A basic block is a sequence of instructions with  No embedded branches (except at end)  No branch targets (except at beginning) A compiler identifies basic blocks for optimization An advanced processor can accelerate execution of basic blocks 9

More Conditional Operations  Less than  Greater than  Combination of logical operations 10

More Conditional Operations  Set result to 1 if a condition is true  Otherwise, set to 0  slt rd, rs, rt  if (rs < rt) rd = 1; else rd = 0;  slti rt, rs, constant  if (rs < constant) rt = 1; else rt = 0;  Use in combination with beq, bne slt $t0, $s1, $s2 # if ($s1 < $s2) bne $t0, $zero, L # branch to L 11

Exercise  Convert the following C++ statement into MIPS if (i>j and i<k) { a++; } Assume i in $s0, j in $s1, k in $s2, a in $s3 12

Exercise if (i>j and i<k) { a++; } Assume i in $s0, j in $s1, k in $s2, a in $s3 slt $t0, $s1, $s0 slt $t1, $s0, $s2 and $t0, $t0, $t1 beq $t0, $zero, L addi $s3, $s3, 1 L: … 13

Better Solution if (i>j and i<k) { a++; } Assume i in $s0, j in $s1, k in $s2, a in $s3 slt $t0, $s1, $s0 beq $t0, $zero, L slt $t0, $s0, $s2 beq $t0, $zero, L addi $s3, $s3, 1 L: … 14

Branch Instruction Design  Why not blt, bge, etc?  Hardware for <, ≥, … slower than =, ≠  Combining with branch involves more work per instruction, requiring a slower clock  All instructions penalized!  beq and bne are the common case  This is a good design compromise 15

Signed vs. Unsigned  Signed comparison: slt, slti  Unsigned comparison: sltu, sltui  Example  $s0 =  $s1 =  slt $t0, $s0, $s1 # signed –1 < +1  $t0 = 1  sltu $t0, $s0, $s1 # unsigned +4,294,967,295 > +1  $t0 = 0 16

Branch Addressing  Branch instructions specify  Opcode, two registers, target address  Most branch targets are near branch  Forward or backward oprsrtconstant or address 6 bits5 bits 16 bits PC-relative addressing Target address = PC + offset × 4 PC already incremented by 4 by this time 17

Jump Addressing  Jump ( j and jal ) targets could be anywhere in text segment  Encode full address in instruction opaddress 6 bits 26 bits (Pseudo)Direct jump addressing Target address = PC 31…28 : (address × 4) 18

Target Addressing Example  Loop code from earlier example  Assume Loop at location Loop: sll $t1, $s3, add $t1, $t1, $s lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, j Loop Exit: …

Branching Far Away  If branch target is too far to encode with 16-bit offset, assembler rewrites the code  Example beq $s0,$s1, L1 ↓ bne $s0,$s1, L2 j L1 L2:… 20

Addressing Mode Summary 21

Summary  Conditional Instructions  beq  bne  j  slt, slti  sltu, sltui  Converting a C Program to MIPS  Branch Addressing 22

What I want you to do  Review Chapter 2  Prepare for assignment 4 23