ECE331: Hardware Organization and Design

Similar documents
ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Lecture 5: Procedure Calls

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

ECE331: Hardware Organization and Design

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

ECE232: Hardware Organization and Design

Chapter 2A Instructions: Language of the Computer

Lecture 5: Procedure Calls

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Compiling Code, Procedures and Stacks

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

EEC 581 Computer Architecture Lecture 1 Review MIPS

ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Chapter 3. Instructions:

Chapter 2. Instructions:

CS3350B Computer Architecture

Levels of Programming. Registers

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

CS 110 Computer Architecture Lecture 6: More MIPS, MIPS Functions

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Lectures 3-4: MIPS instructions

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

ECE260: Fundamentals of Computer Engineering

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

Computer Architecture

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

EN164: Design of Computing Systems Lecture 11: Processor / ISA 4

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Review of Activation Frames. FP of caller Y X Return value A B C

Chapter 2: Instructions:

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

ECE 30 Introduction to Computer Engineering

Lecture 6: Assembly Programs

COMPUTER ORGANIZATION AND DESIGN

CS3350B Computer Architecture MIPS Introduction

Thomas Polzer Institut für Technische Informatik

EE 361 University of Hawaii Fall

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

CSE Lecture In Class Example Handout

Instructions: Language of the Computer

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

SPIM Instruction Set

CENG3420 Lecture 03 Review

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.

CS222: MIPS Instruction Set

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Instructions: Assembly Language

Programming with QtSpim: A User s Manual

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions

CS/COE1541: Introduction to Computer Architecture

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

Lecture 4: MIPS Instruction Set

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

Chapter 2. Instruction Set Architecture (ISA)

Lecture 7: Procedures

CS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons

ECE232: Hardware Organization and Design

More C functions and Big Picture [MIPSc Notes]

Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures

Introduction to MIPS Processor

Instruction Set Architecture

ECE369. Chapter 2 ECE369

CS61C : Machine Structures

CS 61c: Great Ideas in Computer Architecture

Machine Instructions - II. Hwansoo Han

MIPS%Assembly% E155%

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

CS 316: Procedure Calls/Pipelining

Compiling Techniques

CSCE 5610: Computer Architecture

MIPS Instruction Set Architecture (2)

instructions aligned is little-endian

Course Administration

We can emit stack-machine-style code for expressions via recursion

CS61C : Machine Structures

Programming the processor

Transcription:

ECE331: Hardware Organization and Design Lecture 7: MIPs Decision-Making Instructions Working with Procedures Adapted from Computer Organization and Design, Patterson & Hennessy, UCB

Overview Computers need to make decisions Microprocessors support conditional operations Operations typically called branch operations Connections with common Java and C language constructs If, else, switch, for loops, do loops Conditional instructions have a specific format To accomplish complicated tasks, we use the concept of procedures ECE331: Decision Making Instructions 2

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 ECE331: Decision Making Instructions 3

Conditional and Unconditional branches Conditional branch beq $t0, $t1, L1 bne $t0, $zero, -25 Number of instructions to jump (can be negative) Unconditional branch: j L1 jr $s5 (useful for large case statements and big jumps) Jump register ECE331: Decision Making Instructions 4

while statement while ( condition ) { statements } while_start_label: # MIPS code for the # condition expression #(if condition satisfied set $t0=1) beq $t0, $zero, while_end_label # MIPS code for the statements j while_start_label while_end_label: ECE331: Decision Making Instructions 5

do-while statement do { statements } while ( condition ); do_start_label: # MIPS code for the statements do_cond_label: # MIPS code for the # condition expression #(if condition satisfied set $t0=1) beq $t0, $zero, do_end_label j do_start_label do_end_label: ECE331: Decision Making Instructions 6

for loop for ( init ; condition ; incr ) { statements } # MIPS code for the init expression for_start_label: # MIPS code for the condition # expression for_end_label: # (if condition satisfied set $t0=1) beq $t0, $zero, for_end_label # MIPS code for the statements # MIPS code for the incr expression j for_start_label ECE331: Decision Making Instructions 7

switch statement switch ( expr ) { } case const1: statement1 case const2: statement2... case constn: statementn default: default-statement ECE331: Decision Making Instructions 8

MIPS code for switch statement # MIPS code for $t0=expr beq $t0, const1, switch_label_1 beq $t0, const2, switch_label_2... beq $t0, constn, switch_label_n j switch_default switch_label_1: # MIPS code to compute statement1 switch_label_2: # MIPS code to compute statement2... switch_default: # MIPS code to compute default-statement switch_end_label: ECE331: Decision Making Instructions 9

Comparisons - What about <,, >,? bne, beq provide equality comparison slt (set on less than) provides magnitude comparison slt $t0,$s3,$s4 # if $s3<$s4 $t0=1; # else $t0=0; Combine with bne or beq to branch: slt $t0,$s3,$s4 # if (a<b) condition register bne $t0,$zero,less # goto Less; Why not include a blt instruction in hardware? Supporting in hardware would lower performance Assembler provides this function if desired (by generating the two instructions) ECE331: Decision Making Instructions 10

Switch Example switch (i) { //Assume i is in $s1 and j is in $s2; case 0: j = 3; break; case 1: j = 5; break; case 2: ; case 3: j = 11; break; case 4: j = 13; break; default: j = 17; } main: add $t0, $zero, $zero # $t0 = 0, temp. variable beq $t0, $s1, case0 # go to case0 addi $t0, $t0, 1 # $t0 = 1 beq $t0, $s1, case1 # go to case1 addi $t0, $t0, 1 # $t0 = 2 beq $t0, $s1, case2 # go to case2 addi $t0, $t0, 1 # $t0 = 3 beq $t0, $s1, case3 # go to case3 addi $t0, $t0, 1 # $t0 = 4 beq $t0, $s1, case4 # go to case4 j default # go to default case case0: addi $s2, $zero, 3 # j = 3 j finish # exit switch block ECE331: Decision Making Instructions 11

SPIM Example switch (i) { //Assume i is in $s1 and j is in $s2; case 0: j = 3; break; case 1: j = 5; break; case 2: ; case 3: j = 11; break; case 4: j = 13; break; default: j = 17; } main: add $t0, $zero, $zero # $t0 = 0, temp. variable used in switch beq $t0, $s1, case0 # go to case0 addi $t0, $t0, 1 # $t0 = 1 beq $t0, $s1, case1 # go to case1 addi $t0, $t0, 1 # $t0 = 2 beq $t0, $s1, case2 # go to case2 addi $t0, $t0, 1 # $t0 = 3 beq $t0, $s1, case3 # go to case3 addi $t0, $t0, 1 # $t0 = 4 beq $t0, $s1, case4 # go to case4 j deflt # go to default case case0: addi $s2, $zero, 3 # j = 3 j fin # exit switch block ECE331: Decision Making Instructions 12

Working with Procedures: Overview To achieve complex tasks, increase efficiency and to modularize computation, we rely on procedures Procedures have different names in different languages Java: methods C: procedures FORTRAN: subroutines Control flow passes to a new section of code, then returns to after the call MIPs includes registers to support data structures for procedures Goal: Understand what happens when a procedure is called/returns ECE331: Decision Making Instructions 13

Software Conventions for MIPS Registers Register Names Usage by Software Convention $0 $zero Hardwired to zero $1 $at Reserved by assembler $2 - $3 $v0 - $v1 Function return result registers $4 - $7 $a0 - $a3 Function passing argument value registers $8 - $15 $t0 - $t7 Temporary registers, caller saved $16 - $23 $s0 - $s7 Saved registers, callee saved $24 - $25 $t8 - $t9 Temporary registers, caller saved $26 - $27 $k0 - $k1 Reserved for OS kernel $28 $gp Global pointer $29 $sp Stack pointer $30 $fp Frame pointer $31 $ra Return address (pushed by call instruction) $hi $hi High result register (remainder/div, high word/ mult) $lo $lo Low result register (quotient/div, low word/mult) ECE331: Decision Making Instructions 14

Procedures (aka subroutines) Complexity is added to programming through the use of subroutines. Subroutines can serve as intermediaries that branch into other subroutines Or they can be a terminal computation that returns a result to the main trunk of the program Within MIPS, we must adhere to are conventions as to how data is preserved in the 32 registers that make up the computational engine of the processor ECE331: Decision Making Instructions 15

Leaf Procedure Example C code: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; } MIPs assumes that arguments g,, j are in $a0,, $a3 f in $s0 (hence, need to save $s0 on stack) Result in $v0 ECE331: Decision Making Instructions 16

Procedure Calling Steps required 1. The calling program places parameters in registers 2. The calling program transfers control to the procedure (callee) 3. The called procedure acquire storage that it needs from memory 4. The called procedure executes its operations 5. The called procedure places results in registers for the calling program to retrieve. 6. The called procedure reverts the appropriate MIPS registers to their original or correct state. 7. The called procedure returns control to the the next word in memory from which it was called. 8. The calling program proceeds with its calculations ECE331: Decision Making Instructions 17