CS3350B Computer Architecture

Similar documents
CS3350B Computer Architecture MIPS Introduction

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Chapter 2A Instructions: Language of the Computer

Computer Architecture

Instructions: Language of the Computer

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

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

CS3350B Computer Architecture MIPS Instruction Representation

Course Administration

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

MIPS Instruction Set Architecture (1)

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

Architecture I. Computer Systems Laboratory Sungkyunkwan University

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)

Chapter 1. Computer Abstractions and Technology

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

COMPUTER ORGANIZATION AND DESIGN

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

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

ECE232: Hardware Organization and Design

MIPS (SPIM) Assembler Syntax

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

Computer Organization MIPS ISA

Chapter 2. Instructions: Language of the Computer

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

CS222: MIPS Instruction Set

Chapter 2: Instructions:

ECE 154A Introduction to. Fall 2012

CSEE 3827: Fundamentals of Computer Systems

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

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

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

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

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

Instructions: Language of the Computer

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

LECTURE 2: INSTRUCTIONS

Unsigned Binary Integers

Unsigned Binary Integers

CS/COE1541: Introduction to Computer Architecture

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

ECE232: Hardware Organization and Design

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

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

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

Control Instructions

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

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

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

Chapter 2. Baback Izadi Division of Engineering Programs

Course Administration

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

Chapter 3. Instructions:

Chapter 2. Instruction Set Architecture (ISA)

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

CENG3420 Lecture 03 Review

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

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

Reduced Instruction Set Computer (RISC)

Computer Architecture. The Language of the Machine

MIPS%Assembly% E155%

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

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

ECE331: Hardware Organization and Design

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

Reduced Instruction Set Computer (RISC)

Thomas Polzer Institut für Technische Informatik

Computer Architecture Computer Science & Engineering. Chapter 2. Instructions: Language of the Computer BK TP.HCM

Chapter 2. Instructions:

Computer Architecture. Lecture 2 : Instructions

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

ECE260: Fundamentals of Computer Engineering

Computer Architecture. MIPS Instruction Set Architecture

CS 4200/5200 Computer Architecture I

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Lecture 4: MIPS Instruction Set

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2. Instructions: Language of the Computer

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

Chapter 2. Instructions: Language of the Computer. Jiang Jiang

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

EEC 581 Computer Architecture Lecture 1 Review MIPS

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Chapter 2. Instruction Set. The MIPS Instruction Set. Arithmetic Operations. Instructions: Language of the Computer

Computer Architecture

Instruction Set Architecture. "Speaking with the computer"

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

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

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

Communicating with People (2.8)

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

EE 361 University of Hawaii Fall

Levels of Programming. Registers

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

Instruction Set Architectures Part I: From C to MIPS. Readings:

Chapter 4. The Processor. Computer Architecture and IC Design Lab

Transcription:

CS3350B Computer Architecture Winter 2015 Lecture 4.1: MIPS ISA: Introduction Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted d from lectures on Computer Organization and Design, Patterson & Hennessy, 5 th edition, 2013]

Abstraction of Machine Structures Levels of representation Software Hardware Application (ex: browser) Operating Compiler Assembler System (Mac OSX) Processor Memory I/O system Datapath & Control Digital Design Circuit Design Transistors Instruction Set Architecture 2

Instructions: Language of the Computer

Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers had very simple instruction sets Simplified implementation Many modern computers also have simple instruction sets 4

The MIPS Instruction Set Used as the example throughout the book Stanford MIPS commercialized by MIPS Technologies (www.mips.com) Large share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, Typical of many modern ISAs See MIPS Reference Data tear-out card, and Appendixes B and E 5

spim Assembler and Simulator spim is a simulator that runs MIPS32 assembly language programs It provides a simple assembler, debugger and a simple set of operating system services Interfaces: Spim, XSpim, PCSpim, QtSpim (new UI, cross-platform) See installation at and user guide at http://pages.cs.wisc.edu/~larus/spim.html

Arithmetic Operations Add and subtract, three operands Two sources and one destination add a, b, c # a gets b + c All arithmetic operations have this form Design Principle 1: Simplicity favors regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost 7

Arithmetic Example C code: f = (g + h) - (i + j); Compiled MIPS code: add t0, g, h # temp t0 = g + h add t1, i, j # temp t1 = i + j sub f, t0, t1 # f = t0 - t1 8

Register Operands Arithmetic instructions use register operands MIPS has a 32 32-bit register file Use for frequently accessed data Numbered 0 to 31 32-bit data called a word Assembler names $t0, $t1,, $t9 for temporary values $s0, $s1,, $s7 for saved variables Design Principle 2: Smaller is faster c.f. main memory: millions of locations 9

Register Operand Example C code: f = (g + h) - (i + j); f,, j in $s0,, $s4 Compiled MIPS code: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 10

Memory Operands Main memory used for composite data Arrays, structures, dynamic data To apply arithmetic operations Load values from memory into registers Store result from register to memory Memory is byte addressed Each address identifies an 8-bit byte Words are aligned in memory Address must be a multiple of 4 MIPS is Big Endian Most-significant byte at least address of a word c.f. Little Endian: least-significant byte at least address 11

Memory Operand Example 1 C code: g = h + A[8]; g in $s1, h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 4 bytes per word lw $t0, 32($s3) # load word add $s1, $s2, $t0 offset base register 12

Memory Operand Example 2 C code: A[12] = h + A[8]; h in $s2, base address of A in $s3 Compiled MIPS code: Index 8 requires offset of 32 lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word 13

Registers vs. Memory Registers are faster to access than memory Operating on memory data requires loads and stores More instructions to be executed Compiler must use registers for variables as much as possible Only spill to memory for less frequently used variables Register optimization is important! 14

Immediate Operands Constant data specified in an instruction addi $s3, $s3, 4 No subtract immediate instruction Just use a negative constant addi $s2, $s1, -1 Design Principle i 3: Make the common case fast Small constants are common Immediate operand avoids a load instruction 15

The Constant Zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten Useful for common operations E.g., move between registers add $t2, $s1, $zero 16

Overview: MIPS R3000 ISA Instruction Categories Computational Registers Load/Store R0 - R31 Jump and Branch Floating Point coprocessor Memory Management Special PC HI LO 3 Basic Instruction Formats: all 32 bits wide OP OP rs rt rd sha funct rs rt immediate R-format I-format OP jump target J-format 17

MIPS Register Convention Name Register Number Usage Preserve on call? $zero 0 constant 0 (hardware) n.a. $at 1 reserved for assembler n.a. $v0 - $v1 2-3 returned values no $a0 - $a3 4-7 arguments yes $t0 - $t7 8-15 temporaries no $s0 - $s7 16-23 saved values yes $t8 - $t9 24-25 temporaries no $k 26-27 Interrupt/trap handler yes $gp 28 global pointer yes $sp 29 stack pointer yes $fp 30 frame pointer yes $ra 31 return addr (hardware) yes 18

MIPS ISA Selected Instruction Set Category Instr OP/funct Example Meaning Arithmetic add R 0/32 add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract R 0/34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 add immediate I 8 addi $s1, $s2, 6 $s1 = $s2 + 6 or immediate I 13 ori $s1, $s2, 6 $s1 = $s2 v 6 Data load word I 35 lw $s1, 24($s2) $s1 = Memory($s2+24) Transfer store word I 43 sw $s1, 24($s2) Memory($s2+24) = $s1 load byte I 32 lb $s1, 25($s2) $s1 = Memory($s2+25) store byte I 40 sb $s1, 25($s2) Memory($s2+25) = $s1 load upper imm I 15 lui $s1, 6 $s1 = 6 * 2 16 Cond. br on equal I 4 beq $s1, $s2, L if ($s1==$s2) go to L Branch br on not equal I 5 bne $s1, $s2, L if ($s1!= $s2) go to L set on less than R 0/42 slt $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than immediate I 10 slti $s1, $s2, 6 if ($s2<6) $s1=1 else $s1=0 Uncond. jump J 2 j 250 go to 1000 Jump jump register R 0/8 jr $t1 go to $t1 jump and link J 3 jal 250 go to 1000; $ra=pc+4 19

Unsigned Binary Integers Given an n-bit number x = x + n 1 n 2 1 0 n 12 + xn 22 + L+ x12 x02 Range: 0 to +2 n 1 Example 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0 2 2 +1 2 1 +1 2 0 = 0 + + 8 + 0 + 2 + 1 = 11 10 Using 32 bits 0 to +4,294,967,295,96, 95 20

2s-Complement Signed Integers Given an n-bit number x = x + n 1 n 2 1 0 n 12 + xn 22 + L+ x12 x02 Range: 2 n 1 to +2 n 1 1 Example 1111 1111 1111 1111 1111 1111 1111 1100 2 = 1 2 31 + 1 2 30 + + 1 2 2 +0 2 1 +0 2 0 = 2,147,483,648 + 2,147,483,644 = 4 10 Using 32 bits 2,147,483,648, 8 to +2,147,483,647, 21

2s-Complement Signed Integers Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers ( 2 n 1 ) can t be represented Non-negative numbers have the same unsigned and 2s-complement representation Some specific numbers 0: 0000 0000 0000 1: 1111 1111 1111 Most-negative: 1000 0000 0000 Most-positive: 0111 1111 1111 22

Signed Negation Complement and add 1 Complement means 1 0, 0 1 x + x = 1111...1112 = 1 2 x + 1= x Example: negate +2 +2 = 0000 0000 0010 2 2 = 1111 1111 1101 2 + 1 = 1111 1111 1110 2 23

Sign Extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left c.f. unsigned values: extend with 0s Examples: pes 8-bit bttoto 16-bit 6bt +2: 0000 0010 => 0000 0000 0000 0010 2: 1111 1110 => 1111 1111 1111 1110 24

Next Lecture: MIPS Instruction Representation 25