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

Similar documents
ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 5 2/22/2018

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

Lecture 5: Procedure Calls

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

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design

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

ECE331: Hardware Organization and Design

Control Instructions

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

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

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

MIPS%Assembly% E155%

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Reduced Instruction Set Computer (RISC)

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

Chapter 2A Instructions: Language of the Computer

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

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

Reduced Instruction Set Computer (RISC)

Lecture 4: MIPS Instruction Set

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

Thomas Polzer Institut für Technische Informatik

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS 61c: Great Ideas in Computer Architecture

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

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

Lecture 5: Procedure Calls

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Computer Architecture. The Language of the Machine

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

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

Levels of Programming. Registers

COMPUTER ORGANIZATION AND DESIGN

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Computer Architecture. MIPS Instruction Set Architecture

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

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

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

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

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

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

CS/COE1541: Introduction to Computer Architecture

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

The MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Course Administration

MIPS Instruction Set Architecture (2)

Computer Architecture

MIPS Reference Guide

Chapter 2. Instructions: Language of the Computer

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter 2: Instructions:

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

M2 Instruction Set Architecture

CS 351 Exam 2 Mon. 11/2/2015

ECE331: Hardware Organization and Design

MIPS Instruction Set

All instructions have 3 operands Operand order is fixed (destination first)

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

Course Administration

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Machine Instructions - II. Hwansoo Han

Instructions: Language of the Computer

Computer Organization & Design

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

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

Instruction Set Architecture

CS3350B Computer Architecture MIPS Introduction

SPIM Instruction Set

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

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

Instructions: Assembly Language

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

MIPS Assembly Language. Today s Lecture

CENG3420 Lecture 03 Review

EE 361 University of Hawaii Fall

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Chapter 2. Instruction Set Architecture (ISA)

ECE331: Hardware Organization and Design

CS222: MIPS Instruction Set

Lectures 3-4: MIPS instructions

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS3350B Computer Architecture

Computer Organization MIPS ISA

Transcription:

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

Study Jams Leader: Chris Bartoli Tuesday 5:30-6:45pm Elab 325 Wednesday 8:30-9:45pm Elab 325

Today s Discussion Topics Conditional Operations Branches + Jumps Loops (if, while, etc.) Procedures

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 ECE331: Logic Operations + Intro to Conditionals

MIPS Conditional Branch Instructions! Conditional branches allow decision making beq R1, R2, LABEL if R1==R2 goto LABEL bne R3, R4, LABEL if R3!=R4 goto LABEL beq $s1, $s2, 25 if ($s1==$s2) PC = PC + 4 + 4*25 else PC = PC + 4 {! Example C Code if (i==j) goto L1; f = g + h; L1: f = f - i; Address of next sequential instruction Offset in bytes! Assembly beq $s3, $s4, L1 add $s0, $s1, $s2 L1: sub $s0, $s0, $s3 ECE331: Logic Operations + Intro to Conditionals

Binary Representation - Branch 6 bits 5 bits 5 bits 16 bits op rs rt offset I-Format! Branch instructions use I-Format! offset is added to PC when branch is taken beq r0, r1, offset has the effect: Conversion to byte offset if (r0==r1) pc = pc + 4 + (offset << 2) else pc = pc + 4; If offset is a positive number! Offset is specified in instruction words ECE331: Logic Operations + Intro to Conditionals

Binary Representation - Jump 6 bits 26 bits op address! Jump Instruction uses J-Format (op=2)! What happens during execution? PC = PC[31:28] : (IR[25:0] << 2) Concatenate upper 4 bits of PC to form complete 32-bit address Conversion to byte offset ECE331: Logic Operations + Intro to Conditionals

Compiling If Statements! C code: if (i==j) f = g+h; else f = g-h; f, g, in $s0, $s1,! Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit: Assembler calculates addresses ECE331: Logic Operations + Intro to Conditionals

Compiling Loop Statements! C code: while (save[i] == k) 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: Array base address, $s6 Address of save[i], $t1 32 bits " 4 bytes Save[0] Save[1] Save[2] Save[3] Save[4] ECE331: Logic Operations + Intro to Conditionals

Procedures Also known as methods, subroutines, functions, Make a call, give control, return Split responsibilities for the data Calling function Called function

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

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

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

1 M I P S Reference Data CORE INSTRUCTION SET OPCODE FOR- / FUNCT NAME, MNEMONIC MAT OPERATION (in Verilog) (Hex) Add add R R[rd] = R[rs] + R[rt] (1) 0 / 20 hex Add Immediate addi I R[rt] = R[rs] + SignExtImm (1,2) 8 hex Add Imm. Unsigned addiu I R[rt] = R[rs] + SignExtImm (2) 9 hex Add Unsigned addu R R[rd] = R[rs] + R[rt] 0 / 21 hex And and R R[rd] = R[rs] & R[rt] 0 / 24 hex And Immediate andi I R[rt] = R[rs] & ZeroExtImm (3) c hex if(r[rs]==r[rt]) Branch On Equal beq I 4 PC=PC+4+BranchAddr (4) hex if(r[rs]!=r[rt]) Branch On Not Equal bne I 5 PC=PC+4+BranchAddr (4) hex Jump j J PC=JumpAddr (5) 2 hex Jump And Link jal J R[31]=PC+8;PC=JumpAddr (5) 3 hex Jump Register jr R PC=R[rs] 0 / 08 hex R[rt]={24 b0,m[r[rs] Load Byte Unsigned lbu I 24 +SignExtImm](7:0)} (2) hex Load Halfword R[rt]={16 b0,m[r[rs] lhu I 25 Unsigned +SignExtImm](15:0)} (2) hex Load Linked ll I R[rt] = M[R[rs]+SignExtImm] (2,7) 30 hex NAME NUMBER USE $zero 0 The Constant Value 0 $at 1 Assembler Temporary $v0-$v1 2-3 Values for Function Results and Expression Evaluation $a0-$a3 4-7 Arguments $t0-$t7 8-15 Temporaries $s0-$s7 16-23 Saved Temporaries $t8-$t9 24-25 Temporaries $k0-$k1 26-27 Reserved for OS Kernel $gp 28 Global Pointer $sp 29 Stack Pointer $fp 30 Frame Pointer $ra 31 Return Address Load Upper Imm. lui I R[rt] = {imm, 16 b0} f hex Load Word lw I R[rt] = M[R[rs]+SignExtImm] (2) 23 hex Nor nor R R[rd] = ~ (R[rs] R[rt]) 0 / 27 hex Or or R R[rd] = R[rs] R[rt] R[rt](15:0) (2) 0 / 25 hex Or Store Immediate Word sw I R[rt] M[R[rs]+SignExtImm] = ZeroExtImm = R[rt] (3) (2) 2b d hex Subtract sub R R[rd] = R[rs] - R[rt] (1) 0 / 22 hex 0 / 23