Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Similar documents
Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

Reduced Instruction Set Computer (RISC)

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

Reduced Instruction Set Computer (RISC)

MIPS%Assembly% E155%

CENG3420 Lecture 03 Review

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

Chapter 2A Instructions: Language of the Computer

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

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

Computer Architecture. The Language of the Machine

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Control Instructions

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

COMPUTER ORGANIZATION AND DESIGN

MIPS Instruction Set Architecture (2)

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

Thomas Polzer Institut für Technische Informatik

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

CS 61c: Great Ideas in Computer Architecture

Architecture II. Computer Systems Laboratory Sungkyunkwan University

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

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

Lecture 5: Procedure Calls

MIPS Reference Guide

Computer Architecture

Instructions: Language of the Computer

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

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

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

CENG3420 L03: Instruction Set Architecture

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

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

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

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

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

Computer Organization MIPS ISA

Course Administration

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

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

Machine Instructions - II. Hwansoo Han

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture. MIPS Instruction Set Architecture

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

MIPS Instruction Set

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

ECE232: Hardware Organization and Design

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

Instructions: Language of the Computer

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

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

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

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

ECE 15B Computer Organization Spring 2010

CS3350B Computer Architecture MIPS Introduction

We will study the MIPS assembly language as an exemplar of the concept.

MIPS Memory Access Instructions

SPIM Instruction Set

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

MIPS Assembly Language. Today s Lecture

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

Computer Architecture

The MIPS Instruction Set Architecture

CS222: MIPS Instruction Set

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

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

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

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

MIPS Instruction Reference

Concocting an Instruction Set

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

CPS311 - COMPUTER ORGANIZATION. A bit of history

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Chapter 2: Instructions:

Computer Organization and Components

Lecture 5: Procedure Calls

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

CS61C : Machine Structures

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

EEC 581 Computer Architecture Lecture 1 Review MIPS

ece4750-tinyrv-isa.txt

Q1: /30 Q2: /25 Q3: /45. Total: /100

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

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

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

MIPS (SPIM) Assembler Syntax

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

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

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

CS3350B Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Concocting an Instruction Set

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

CS61C : Machine Structures

Transcription:

Computer Architecture Instruction Set Architecture part 2 Mehran Rezaei

Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a MIPS Interpreter MIPS and Register File Register Naming convention 2

Today s class Register Naming Convention, a review MIPS Arithmetic, Load/store and logical instructions slt and jr instructions Branches and jumps pc relative addressing 3

Naming Convention for registers 0 zero constant 0 1 at reserved for assembler 2 v0 expression evaluation & 3 v1 function results 4 a0 arguments 5 a1 6 a2 7 a3 8 t0 temporary: caller saves... (callee can clobber) 15 t7 16 s0 callee saves... (caller can clobber) 23 s7 24 t8 temporary (cont d) 25 t9 26 k0 reserved for OS kernel 27 k1 28 gp Pointer to global area 29 sp Stack pointer 30 fp frame pointer 31 ra Return Address (HW) 4

Example Compile A[20] += A[8]; address of A[0] is in $s1 5

Anatomy of data transfer inst. lw $t0, 5($s1) offset Base register Index register (why?) 6

Instructions, so far Translate to machine code A[20] +=A[8]; 7

Shifters Two kinds: logical-- value shifted in is always "0" "0" msb lsb "0" arithmetic-- on right shifts, sign extend msb lsb "0" Note: these are single bit shifts. A given instruction might request 0 to 32 bits to be shifted! 8

MIPS logical instructions and $1,$2,$3 $1 = $2 & $3 or $1,$2,$3 $1 = $2 $3 nor $1,$2,$3 $1 = ~($2 $3) andi $1,$2,10 $1 = $2 & 10 ori $1,$2,10 $1 = $2 10 sll $1,$2,10 $1 = $2 << 10 srl $1,$2,10 $1 = $2 >> 10 sra $1,$2,10 $1 = $2 >> 10 9

A different style Make access to small constant fast Application for(j=0;j<10;j++) A[j]++; Profile analysis shows: In gcc 52% In spice 69% Of arithmetic instructions involve constants op rs rt immediate addi $s4,$s4,4 10

A tiny problem What if the immediate value is beyond the range that 16 bits can provide By the way, what is this range? lui $s1,5 $s1 0000 0000 0000 0101 0000 0000 0000 0000 What if I want to load 5*2 16 +25 to $s1? Who is responsible for doing this? MIPS provides $at for such cases 11

American Std Code for Info. Interchange (ASCII) 12

Load and store bytes lb $t0,0($sp) sb $t1,4($sp) $sp 13

Alignment MIPS requires that all words start at addresses that are multiples of 4 bytes 0 1 2 3 Aligned Not Aligned Called Alignment: objects must fall on address that is multiple of their size. Why do we care? 14

Endian-ness or Edianess Big Endian: Leftmost byte is word address Little Endian: Rightmost byte is word address 3 2 1 0 little endian msb lsb Big endian 0 1 2 3 15

MIPS arithmetic instruction format R-type: I-Type: 31 25 20 15 5 0 op Rs Rt Rd funct op Rs Rt Immed 16 Type op funct ADDI 10 xx ADDIU 11 xx SLTI 12 xx SLTIU 13 xx ANDI 14 xx ORI 15 xx XORI 16 xx LUI 17 xx Type op funct ADD 00 40 ADDU 00 41 SUB 00 42 SUBU 00 43 AND 00 44 OR 00 45 XOR 00 46 NOR 00 47 Type op funct 00 50 00 51 SLT 00 52 SLTU 00 53 16

New instructions lbu $t0,0($s0) lb $t0,0($s0) Extension $t0 94H $s0 94H 17

Addition/Subtraction Examples 0X4E + 0X1F 0X4E 0X1F Overflow operation condition result A + B A > 0 B > 0 < 0 A + B A < 0 B < 0 > 0 A - B A > 0 B < 0 < 0 A - B A < 0 B > 0 > 0 18

What to do on overflow? Ignore Programmer is responsible for Leave it to OS Either completely takes care of it Or signals the application What does MIPS do? For signed operation (if overflow occurs) it throws an exception It ignores the overflow of unsigned operations 19

If an overflow is detected PC -> EPC mfc0 places EPC to a register ($k0 and $k1 are used for such a purpose) Jump to a code which services the interrupt based on the type of the interrupt Resolve the problem Return with an error code Abort program 20

More in overflow No means to check if overflow occurs in MIPS Question: How would I indicate that an overflow occur? For signed operations Unsigned operations 21

Instructions for making decisions Conditional/Unconditional branches beq bne j Example Compile $s1,$s2, L1 $s3,$s4, L2 L3 if(i == j) f = g + h k; else f = g + h + k; Given i: $s1, j: $s2, f: $s3, g: $s4, h: $s5, and k: $s6 22

More examples compile Loop: g += A[i]; i += j; if(i!= h) goto Loop; 23

Compile a while loop while (save[j] == k) j += n; Loop: if(save[j]!= k) goto Exit; j += n; goto Loop; Exit: 24

Hierarchical Interpretation of an Application (Executable file) Executable File Object Object procedure procedure Basic block Basic block instruction 25

New Instructions slt $s1,$s2,$s3 if $s2 < $s3 set $s1 to 1 else set $s1 to 0 jr $s0 jump to the address given by the $s0 26

Branches (Conditional) I-Type bne $s0, $s1, Exit 5 16 17 Exit What seems to be the problem? 27

PC Relative addressing MIPS adds the content of PC to the immediate field to provide a wider range. Why? 50% of conditional branch targets in gcc are smaller than 16 instructions apart from their origin bne $s0, $s1, address PC = (PC + 4) + 4*address What is the range of the branching? What if you need branch farther than that? We will come back to this shortly. 28

Unconditional Branches J-Type opcode Target address What range could it provide? Keep in your mind that J-Type is also word address In J-Type 4 upper bits of the PC will be unchanged Do not place the program across the boundary of 256 MB : 64 million instructions 29

Final Question bne $s1,$s2, L1 and L1 is beyond [-2 17, 2 17 ] apart from PC 30

Function calls and Procedures What is the difference between a function call and a procedure? Leaf versus Recursive What is needed for supporting the procedure calls by hardware? 31

Registers 0 zero constant 0 1 at reserved for assembler 2 v0 expression evaluation & 3 v1 function results 4 a0 arguments 5 a1 6 a2 7 a3 8 t0 temporary: caller saves... (callee can clobber) 15 t7 16 s0 callee saves... (caller can clobber) 23 s7 24 t8 temporary (cont d) 25 t9 26 k0 reserved for OS kernel 27 k1 28 gp Pointer to global area 29 sp Stack pointer 30 fp frame pointer 31 ra Return Address (HW) 32

Instructions jal x (again jal is also word address) $ra= PC + 4 Jump to the address 4*x Instruction type is J with opcode 3 jr $ra Which we have seen already and jump to the instruction whose address is in the register; in this case we have return address register Instruction type is R with opcode 0 and func 8 33

Steps for Making a Procedure Call 1. Save necessary values onto stack 2. Assign argument(s), if any $a0 - $a3 for arguments 3. jal call 4. Restore values from stack 34

Steps taken by the Callee 1. Acquire the storage resources needed If need any of $s registers, should save them onto the stack, and after use restore them back to the registers 2. Perform the desired task 3. Place the result values in $v0 and $v1 4. jr $ra 35

Rules for Procedures Called with a jal instruction, returns with a jr $ra Accepts up to 4 arguments in $a0, $a1, $a2 and $a3 Return value is always in $v0 (and if necessary in $v1) Must follow register conventions (even in functions that only you will call)! 36

Hand - Compile Example int leaf(int g,int h,int i,int j){ int f; f = (g + h) (i + j); return f; } 37

MIPS memory layout 38

Example Hand - compile int leaf(int arg){ int l=10; return l*arg; } main(){ int j; j = leaf(5); } 39

Recursive Calls int fact(int n){ if(n <= 1) return 1; return n * fact(n-1); } int fact(int n){ int a; int b; if(n <= 1) return 1; a = fact(n 1); b = n * a; return b; } 40

Recursive Calls (Cont d) main(){ int j=fact(3); } fact(3){ a=fact(2); b=3*a; return b; } fact(2){ a=fact(1); b=2*a; return b; } 41

How to represent strings Use the beginning of the string for the length (4 bytes) Accompany string with a variable length Use a special character at the end of the string as an indication of string s end (C uses null for that purpose) 42

Example Hand compile strcat(char s[], char t[]){ int i,j; i=j=0; while(s[i]!= 0) i++; while((s[i++] = t[j++])!= 0); } 43

Some Words about SPIM Comments, Identifiers, Labels, Number representation, Strings, and Special Characters Some assembly directives.text <addr>.data <addr> Mydata:.word 1,2,3.ascii str1.asciiz str2 44

System Calls What is a system call? SPIM provides a small set of system calls How does it work? Load syscall code into $v0 Load arguments (if any) into $a0,, $a3 Issue syscall 45