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

Similar documents
Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Instructions: Language of the Computer

Computer Organization MIPS ISA

Instructions: Language of the Computer

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

14:332:331. Lecture 1

Chapter 2A Instructions: Language of the Computer

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

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

Control Instructions

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

Instructions: Language of the Computer

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

Chapter 2: Instructions:

CENG3420 L03: Instruction Set Architecture

CS222: MIPS Instruction Set

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

CENG3420 Lecture 03 Review

Chapter 2. Instructions:

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

Computer Architecture

Instruction Set Architecture. "Speaking with the computer"

Chapter 3. Instructions:

MIPS Instruction Set Architecture (1)

Lecture 3 Machine Language. Instructions: Instruction Execution cycle. Speaking computer before voice recognition interfaces

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

CS3350B Computer Architecture MIPS Introduction

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

ECE369. Chapter 2 ECE369

Computer Architecture

ECE232: Hardware Organization and Design

CS/COE1541: Introduction to Computer Architecture

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

ECE 486/586. Computer Architecture. Lecture # 7

Lecture 4: MIPS Instruction Set

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

Instruction Set Design and Architecture

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

CpE 442 Introduction To Computer Architecture Lecture 1

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

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

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

CS3350B Computer Architecture

The Single Cycle Processor

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

CS222: Dr. A. Sahu. Indian Institute of Technology Guwahati

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

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

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Reduced Instruction Set Computer (RISC)

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

Reduced Instruction Set Computer (RISC)

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

CS3350B Computer Architecture MIPS Instruction Representation

ECE232: Hardware Organization and Design

Topic Notes: MIPS Instruction Set Architecture

Architecture I. Computer Systems Laboratory Sungkyunkwan University

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

EC 413 Computer Organization

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

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

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

Typical Processor Execution Cycle

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

ECE331: Hardware Organization and Design

Processor (I) - datapath & control. Hwansoo Han

ECE 154A Introduction to. Fall 2012

MIPS%Assembly% E155%

Computer Architecture

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

Chapter 2 Instruction: Language of the Computer

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

ECE232: Hardware Organization and Design

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

Computer Architecture. The Language of the Machine

MIPS Processor Overview

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

Instruction Set Architecture (ISA)

Five classic components

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

COMPUTER ORGANIZATION AND DESIGN

Levels of Programming. Registers

Introduction. Datapath Basics

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

ECE 468 Computer Architecture and Organization Lecture 1

Review of instruction set architectures

Hakim Weatherspoon CS 3410 Computer Science Cornell University

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

Computer Model. What s in a computer? Processor Memory I/O devices (keyboard, mouse, LCD, video camera, speaker, disk, CD drive, )

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

Transcription:

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L09.1 Smith Spring 2008

MIPS - originally an acronym for Microprocessor without Interlocked Pipeline Stages) M230 L09.2 Smith Spring 2008

M230 L09.3 Smith Spring 2008

Below the Program M230 L09.5 Smith Spring 2008

Below the Program Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000... M230 L09.5 Smith Spring 2008

Below the Program Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000... M230 L09.5 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000... M230 L09.5 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 C compiler Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000... M230 L09.5 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 C compiler Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000... assembler M230 L09.5 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages Allow the programmer to think in a more natural language and for their intended use (Fortran for scientific computation, Cobol for business programming, Lisp for symbol manipulation, ) As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages Allow the programmer to think in a more natural language and for their intended use (Fortran for scientific computation, Cobol for business programming, Lisp for symbol manipulation, ) Improve programmer productivity more understandable code that is easier to debug and validate As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages Allow the programmer to think in a more natural language and for their intended use (Fortran for scientific computation, Cobol for business programming, Lisp for symbol manipulation, ) Improve programmer productivity more understandable code that is easier to debug and validate Improve program maintainability As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages Allow the programmer to think in a more natural language and for their intended use (Fortran for scientific computation, Cobol for business programming, Lisp for symbol manipulation, ) Improve programmer productivity more understandable code that is easier to debug and validate Improve program maintainability Allow programmers to be independent of the computer on which they are developed (compilers and assemblers can translate high-level language programs to the binary instructions of any machine) As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Advantages of Higher-Level Languages Higher-level languages Allow the programmer to think in a more natural language and for their intended use (Fortran for scientific computation, Cobol for business programming, Lisp for symbol manipulation, ) Improve programmer productivity more understandable code that is easier to debug and validate Improve program maintainability Allow programmers to be independent of the computer on which they are developed (compilers and assemblers can translate high-level language programs to the binary instructions of any machine) Emergence of optimizing compilers that produce very efficient assembly code optimized for the target machine As a result, very little programming is done today at the assembler level M230 L09.7 Smith Spring 2008

Machine Organization M230 L09.8 Smith Spring 2008

Machine Organization Capabilities and performance characteristics of the principal Functional Units (FUs) e.g., register file, ALU, multiplexors, memories,... M230 L09.8 Smith Spring 2008

Machine Organization Capabilities and performance characteristics of the principal Functional Units (FUs) e.g., register file, ALU, multiplexors, memories,... The ways those FUs are interconnected e.g., buses M230 L09.8 Smith Spring 2008

Machine Organization Capabilities and performance characteristics of the principal Functional Units (FUs) e.g., register file, ALU, multiplexors, memories,... The ways those FUs are interconnected e.g., buses Logic and means by which information flow between FUs is controlled M230 L09.8 Smith Spring 2008

Machine Organization Capabilities and performance characteristics of the principal Functional Units (FUs) e.g., register file, ALU, multiplexors, memories,... The ways those FUs are interconnected e.g., buses Logic and means by which information flow between FUs is controlled The machine s Instruction Set Architecture (ISA) M230 L09.8 Smith Spring 2008

Machine Organization Capabilities and performance characteristics of the principal Functional Units (FUs) e.g., register file, ALU, multiplexors, memories,... The ways those FUs are interconnected e.g., buses Logic and means by which information flow between FUs is controlled The machine s Instruction Set Architecture (ISA) Register Transfer Level (RTL) machine description M230 L09.8 Smith Spring 2008

Major Components of a Computer Processor Devices Control Memory Input Datapath Output M230 L09.9 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Below the Program High-level language program (in C) swap (int v[], int k)... Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 one-to-many one-to-one C compiler assembler M230 L09.11 Smith Spring 2008

Input Device Inputs Object Code 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Processor Devices Control Memory Input Datapath Output M230 L09.12 Smith Spring 2008

Object Code Stored in Memory Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output M230 L09.13 Smith Spring 2008

Processor Fetches an Instruction Processor fetches an instruction from memory Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Where does it fetch from? M230 L09.14 Smith Spring 2008

Control Decodes the Instruction Control decodes the instruction to determine what to execute Processor Control 000000 00100 00010 0001000000100000 Datapath Memory Devices Input Output M230 L09.15 Smith Spring 2008

Datapath Executes the Instruction Datapath executes the instruction as directed by control Processor Control 000000 00100 00010 0001000000100000 Datapath contents Reg #4 ADD contents Reg #2 results put in Reg #2 Memory Devices Input Output M230 L09.16 Smith Spring 2008

Processor Organization M230 L09.17 Smith Spring 2008

Processor Organization Control needs to have the Ability to input instructions from memory Logic and means to control instruction sequencing Logic and means to issue signals that control the way information flows between datapath components Logic and means to control what operations the datapath s functional units perform M230 L09.17 Smith Spring 2008

Processor Organization Control needs to have the Ability to input instructions from memory Logic and means to control instruction sequencing Logic and means to issue signals that control the way information flows between datapath components Logic and means to control what operations the datapath s functional units perform Datapath needs to have the Components - functional units (e.g., adder) and storage locations (e.g., register file) - needed to execute instructions Components interconnected so that the instructions can be accomplished Ability to load data from and store data to memory M230 L09.17 Smith Spring 2008

Processor Organization Control needs to have the Ability to input instructions from memory Logic and means to control instruction sequencing Logic and means to issue signals that control the way information flows between datapath components Logic and means to control what operations the datapath s functional units perform Datapath needs to have the Components - functional units (e.g., adder) and storage locations (e.g., register file) - needed to execute instructions Components interconnected so that the instructions can be accomplished Ability to load data from and store data to memory Where does it load and store from and to? M230 L09.17 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch Decode M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch Decode M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch Exec Decode M230 L09.19 Smith Spring 2008

What Happens Next? Processor Control Datapath Memory 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Devices Input Output Fetch Exec Decode M230 L09.19 Smith Spring 2008

Output Data Stored in Memory At program completion the data to be output resides in memory Processor Memory Devices Control Input Datapath 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 Output M230 L09.20 Smith Spring 2008

Output Data Stored in Memory At program completion the data to be output resides in memory Processor Memory Devices Control Input Datapath 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 Output M230 L09.20 Smith Spring 2008

Output Device Outputs Data Processor Devices Control Memory Input Datapath Output 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 M230 L09.21 Smith Spring 2008

The Instruction Set Architecture software instruction set architecture hardware M230 L09.22 Smith Spring 2008

The Instruction Set Architecture software instruction set architecture hardware M230 L09.22 Smith Spring 2008

The Instruction Set Architecture software instruction set architecture hardware The interface description separating the software and hardware. M230 L09.22 Smith Spring 2008

MIPS R3000 Instruction Set Architecture Instruction Categories Load/Store Computational Jump and Branch Floating Point - coprocessor Memory Management Special Registers R0 - R31 PC HI LO 3 Instruction Formats: all 32 bits wide OP OP OP rs rt rd sa funct rs rt immediate jump target M230 L09.23 Smith Spring 2008

MIPS R3000 Instruction Set Architecture Instruction Categories Load/Store Computational Jump and Branch Floating Point - coprocessor Memory Management Special Registers R0 - R31 PC HI LO 3 Instruction Formats: all 32 bits wide OP OP OP rs rt rd sa funct rs rt immediate jump target Q: How many already familiar with MIPS ISA? M230 L09.23 Smith Spring 2008

Assembly Language Instructions Language of the machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS arithmetic instructions We ll be working with the MIPS instruction set architecture similar to other architectures developed since the 1980's used by NEC, Nintendo, Silicon Graphics, Sony, Design goals: maximize performance, minimize cost, reduce design time, minimize memory space (embedded systems), minimize power consumption (mobile systems) M230 L09.25 Smith Spring 2008

RISC - Reduced Instruction Set Computer RISC philosophy fixed instruction lengths load-store instruction sets limited addressing modes limited operations MIPS, Sun SPARC, HP PA-RISC, IBM PowerPC, Intel (Compaq) Alpha, Instruction sets are measured by how well compilers use them as opposed to how well assembly language programmers use them M230 L09.26 Smith Spring 2008

MIPS Arithmetic Instruction MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs only one operation Each arithmetic instruction specifies exactly three operands destination source1 op source2 Those operands are contained in the datapath s register file ($t0, $s1,$s2) Operand order is fixed (destination first) M230 L09.28 Smith Spring 2008

MIPS Arithmetic Instruction MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs only one operation Each arithmetic instruction specifies exactly three operands destination source1 op source2 Those operands are contained in the datapath s register file ($t0, $s1,$s2) Operand order is fixed (destination first) M230 L09.28 Smith Spring 2008

MIPS Arithmetic Instruction MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs only one operation Each arithmetic instruction specifies exactly three operands destination source1 op source2 Those operands are contained in the datapath s register file ($t0, $s1,$s2) Operand order is fixed (destination first) M230 L09.28 Smith Spring 2008

MIPS Arithmetic Instruction MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs only one operation Each arithmetic instruction specifies exactly three operands destination source1 op source2 Those operands are contained in the datapath s register file ($t0, $s1,$s2) Operand order is fixed (destination first) M230 L09.28 Smith Spring 2008

MIPS Arithmetic Instruction MIPS assembly language arithmetic statement add $t0, $s1, $s2 sub $t0, $s1, $s2 Each arithmetic instruction performs only one operation Each arithmetic instruction specifies exactly three operands destination source1 op source2 Those operands are contained in the datapath s register file ($t0, $s1,$s2) Operand order is fixed (destination first) M230 L09.28 Smith Spring 2008

Compiling More Complex Statements Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d M230 L09.30 Smith Spring 2008

Compiling More Complex Statements Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d sub $t0, $s1, $s2 add $s0, $t0, $s3 M230 L09.30 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that - code density improves (since register are named with fewer bits than a memory location) Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File 32 locations 32 bits - code density improves (since register are named with fewer bits than a memory location) src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 32 locations 32 bits src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 5 32 locations 32 bits src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 5 5 32 locations 32 bits src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 5 5 32 32 locations 32 bits src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 5 5 32 32 locations 32 bits 32 src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

MIPS Register File Operands of arithmetic instructions must be from a limited number of special locations contained in the datapath s register file Holds thirty-two 32-bit registers - With two read ports and - One write port Registers are Faster than main memory Easier for a compiler to use - e.g., (A*B) (C*D) (E*F) can do multiplies in any order vs. stack Can hold variables so that src1 addr src2 addr dst addr write data Register File - code density improves (since register are named with fewer bits than a memory location) 5 5 5 32 32 locations 32 bits 32 32 src1 data src2 data Register addresses are indicated by using $ M230 L09.32 Smith Spring 2008

Naming Conventions for Registers 0 $zero constant 0 (Hdware) 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 (Hdware) M230 L09.33 Smith Spring 2008

Registers vs. Memory Arithmetic instructions operands must be registers, only thirty-two registers provided Processor Devices Control Memory Input Datapath Output Compiler associates variables with registers What about programs with lots of variables? M230 L09.35 Smith Spring 2008

Registers vs. Memory Arithmetic instructions operands must be registers, only thirty-two registers provided Processor Devices Control Memory Input Datapath Output Compiler associates variables with registers What about programs with lots of variables? M230 L09.35 Smith Spring 2008

Registers vs. Memory Arithmetic instructions operands must be registers, only thirty-two registers provided Processor Devices Control Memory Input Datapath Output Compiler associates variables with registers What about programs with lots of variables? M230 L09.35 Smith Spring 2008

Accessing Memory MIPS has two basic data transfer instructions for accessing memory lw $t0, 4($s3) #load word from memory sw $t0, 8($s3) #store word to memory (assume $s3 holds 24 10 ) The data transfer instruction must specify where in memory to read from (load) or write to (store) memory address where in the register file to write to (load) or read from (store) register destination (source) The memory address is formed by summing the constant portion of the instruction and the contents of the second register M230 L09.37 Smith Spring 2008

Accessing Memory MIPS has two basic data transfer instructions for accessing memory 28 lw $t0, 4($s3) #load word from memory sw $t0, 8($s3) #store word to memory (assume $s3 holds 24 10 ) The data transfer instruction must specify where in memory to read from (load) or write to (store) memory address where in the register file to write to (load) or read from (store) register destination (source) The memory address is formed by summing the constant portion of the instruction and the contents of the second register M230 L09.37 Smith Spring 2008

Accessing Memory MIPS has two basic data transfer instructions for accessing memory 28 lw $t0, 4($s3) #load word from memory sw $t0, 8($s3) #store word to memory 32 (assume $s3 holds 24 10 ) The data transfer instruction must specify where in memory to read from (load) or write to (store) memory address where in the register file to write to (load) or read from (store) register destination (source) The memory address is formed by summing the constant portion of the instruction and the contents of the second register M230 L09.37 Smith Spring 2008

MIPS Instructions, so far Category Instr Op Code Example Meaning Arithmetic add 0 and 32 add $s1, $s2, $s3 $s1 = $s2 + $s3 (R format) subtract 0 and 34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 Data load word 35 lw $s1, 100($s2) $s1 = Memory($s2+100) transfer store word 43 sw $s1, 100($s2) Memory($s2+100) = $s1 (I format) M230 L09.38 Smith Spring 2008