Chapter 2: Instructions:

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

Chapter 3. Instructions:

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

Chapter 2. Instruction Set Architecture (ISA)

ECE369. Chapter 2 ECE369

Instructions: Language of the Computer

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

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

CS222: MIPS Instruction Set

Chapter 2. Instructions:

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Computer Architecture

CS/COE1541: Introduction to Computer Architecture

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

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

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

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

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

CS3350B Computer Architecture MIPS Introduction

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

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

Instructions: Language of the Computer

Course Administration

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

CS3350B Computer Architecture

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

Chapter 2A Instructions: Language of the Computer

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

MIPS%Assembly% E155%

Levels of Programming. Registers

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

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

CS3350B Computer Architecture MIPS Instruction Representation

Computer Organization MIPS ISA

Lecture 4: MIPS Instruction Set

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Computer Architecture

Instruction Set Architecture. "Speaking with the computer"

Topic Notes: MIPS Instruction Set Architecture

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

CS 4200/5200 Computer Architecture I

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

Reduced Instruction Set Computer (RISC)

ECE 154A Introduction to. Fall 2012

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

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

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

MIPS Instruction Set Architecture (1)

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

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

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

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

Control Instructions

ECE232: Hardware Organization and Design

Course Administration

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

MIPS (SPIM) Assembler Syntax

MIPS Memory Access Instructions

Instruction Set Design and Architecture

Instruction Set Architectures

Communicating with People (2.8)

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

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

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

COMPUTER ORGANIZATION AND DESIGN

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

Instructions: Language of the Computer

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

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

Computer Architecture. MIPS Instruction Set Architecture

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

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

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

Thomas Polzer Institut für Technische Informatik

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

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

Introduction. Datapath Basics

Chapter 2. Instructions: Language of the Computer

Instructions: Assembly Language

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

Lecture 3: Instruction Set Architecture

Lecture 5: Procedure Calls

Instruction Set Architecture

CENG3420 L03: Instruction Set Architecture

CENG3420 Lecture 03 Review

Systems Architecture I

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

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

CPSC 330 Computer Organization

Computer Architecture. The Language of the Machine

MACHINE LANGUAGE. To work with the machine, we need a translator.

Transcription:

Chapter 2: Instructions: Language of the Computer Computer Architecture CS-3511-2 1

Instructions: To command a computer s hardware you must speak it s language The computer s language is called instruction The computer s vocabulary is called Instruction set MIPS Instruction set Architecture used by NEC, Nintendo, Cisco, Silicon Graphics, Sony, 14 13 12 11 1 9 8 7 6 5 4 3 2 1 Other SPARC Hitachi SH PowerPC Motorola 68K MIPS IA-32 ARM 1998 1999 2 21 22 Computer Architecture CS-3511-2 2

Operations of Computer Hardware MIPS Arithmetic Instruct a computer to add two variables b and c and store the result in a: add a, b, c MIPS Arithmetic Instruction Format: Must have 3 Operands always Order of operands is rigid Instruction performs one operation Design Principle 1: Simplicity favors regularity. Computer Architecture CS-3511-2 3

MIPS Arithmetic examples C code: a = b + c + d; MIPS code: add a, b, c add a, a, d C code: a = b + c + d + e; MIPS code: add a, b, c # puts sum of b and c in a add a, a, d add a, a, e C code d = a e; MIPS code: sub d, a, e Computer Architecture CS-3511-2 4

MIPS Arithmetic Compiling complex C assignments C code: f = (g + h) (i + j); MIPS code: add t, g, h add t1, i, j sub f, t, t1 MIPS arithmetic instruction operates on two source operands and places the result in one destination operand Computer Architecture CS-3511-2 5

MIPS Arithmetic Operands (computer Hardware) Arithmetic instructions operands must be registers Restricted to 32 registers Compiler associates variables with registers The 3 variable operands must be chosen from one of the 32 Registers Why are we limited to 32 Registers: Design Principle 2: Smaller is Faster Effective use of register is key to program performance What about programs with lots of variables? ( we will talk about this shortly) Computer Architecture CS-3511-2 6

MIPS Arithmetic Convention Registers that correspond to variables: $s, $s1, $s2.. Temporary Registers: $t, $t1, $t2.. C code: f = (g + h) (i + j) f -> $s, g -> $s1, h -> $s2, i -> $s3, j -> $s4 add $t, $s1, $s2 add $t1, $s3, $s4 sub $s, $t, $t1 Computer Architecture CS-3511-2 7

MIPS Arithmetic Memory Operand Data Structures (arrays, and structures) Stored in memory Not enough registers to hold them Memory data items must be transferred to registers for Arithmetic operations MIPS instruction set Includes Data Transfer Instructions Computer Architecture CS-3511-2 8

Memory Organization Conceptually a 1-D array with an Address scheme Address is index to array Memory width (w) is 8 bits of data (1 byte) --- word Index points to a byte of memory Computer Architecture CS-3511-2 9

Memory Organization Registers Vs. Memory The size of MIPS word is 32 bits or 4 bytes MIPS Register has larger word than memory 32 bits of data 4 8 12 16 32 bits of data 32 bits of data 32 bits of data 32 bits of data Each MIPS word start at address that is a multiple of 4 2 32 bytes -> byte address 2 32-1 2 3 words -> byte address 2 32-4 Computer Architecture CS-3511-2 1

MIPS Arithmetic Data Transfer Instructions Load word (lw) and Store word (sw) Instruction: C code: MIPS code: A[12] = h + A[8]; lw $t, 32($s3) add $t, $s2, $t sw $t, 48($s3) Destination Destination What is wrong with: add 48($S3), $s2, 32($s3)? Computer Architecture CS-3511-2 11

MIPS So far MIPS Load words but address bytes Performs arithmetic on registers only MIPS Instructions Meaning add $s1, $s2, $s3 $s1 = $s2 + $s3 sub $s1, $s2, $s3 $s1 = $s2 - $s3 lw $s1, 1($s2) $s1 = Memory[$s2 + 1] sw $s1, 1($s2) Memory[$s2 +1] = $s1 Computer Architecture CS-3511-2 12

Machine Language Instructions Arithmetic Instructions MIPS Instructions: Example: add $t, $s1, $s2 # $t = $s1 + $s2 Registers represented by numbers: $t -> 8; $s1 -> 17; $s2 -> 18 Instruction Format (R-Type): op rs rt rd shamt funct 17 18 8 32 Computer Architecture CS-3511-2 13

Machine Language Instructions Arithmetic Instructions add $t, $s1, $s2 op rs rt rd shamt funct 17 18 8 32 11 11 1 1 MIPS Instructions: 32 bits long Computer Architecture CS-3511-2 14

Machine Language Instructions Data Transfer Instructions MIPS Instructions: Example: lw $t, 32($3) # $t gets A[8] Registers represented by numbers: Instruction Format (I-Type): op rs rt Constant Or Address 35 18 8 6 bits 5 bits 5 bits I-Type Instructions: 32 bits long 32 16 bit number Design Principle 4: Good design demands a compromises Computer Architecture CS-3511-2 15

Machine Language Example: C- code: A[3] = h + A[3]; MIPS code: lw $t, 12 ($t1) add $t, $s2, $t sw $t, 12($t1) op rs rt rd addr/ funct shamt 35 9 8 12 Offset 18 8 8 32 43 9 8 12 Computer Architecture CS-3511-2 16

Machine Language Example: C- code: A[3] = h + A[3]; Machine Language op rs rt rd addr/ funct shamt 111 11 1 1 111 11 1 1 1 1111 11 1 1 111 Computer Architecture CS-3511-2 17

Machine Language Let s Summarize Example: C- code: A[3] = h + A[3]; MIPS code: lw $t, 12 ($t1) add $t, $s2, $t sw $t, 12($t1) op rs rt rd addr/ funct shamt 35 9 8 12 18 8 8 32 43 9 8 12 op rs rt rd addr/ funct shamt 111 11 1 1 111 11 1 1 1 1111 11 1 1 111 Computer Architecture CS-3511-2 18

Machine Language Instructions Branch Instructions MIPS conditional branch instructions: beq $s1, $s2, L1 bne $s1, $s2, L1 L1: Example: if ( i == j) f = g + h; - Variables: f, g, h, i, j registers: $s, $s1, $s2, $s3, $s4 bne $s3, $s4, Label add $s, $s1, $s2 Label: Computer Architecture CS-3511-2 19

Machine Language Instructions Branch Instructions MIPS unconditional branch instructions: j Label j Exit Example: if ( i == j) f = g + h; else f = g h; - Variables: f, g, h, i, j registers: $s, $s1, $s2, $s3, $s4 bne $s3, $s4 Else #go to Else if i!= j add $s, $s1, $s2 j Exit Else: sub $s, $s1, $s2 Exit: Computer Architecture CS-3511-2 2

Machine Language Instructions Branch Instructions Instruction Format (J -Type): op 26 bit number J -Type Instructions: 32 bits long Computer Architecture CS-3511-2 21

Machine Language Instructions Compare Instructions if $s3 < $s4 then $t = 1 else $t = slt $t, $s3, $s4 Computer Architecture CS-3511-2 22

Machine Language Instructions Compare Instructions if $s3 < then $t = 1 else $t = slt $t, $s3, $zero $zero maps to Register ( we will talk about constants shortly) Assembler also needs a register to perform instructions Computer Architecture CS-3511-2 23

MIPS register convention Name Register number Usage $zero the constant value $v-$v1 2-3 values for results and expression evaluation $a-$a3 4-7 arguments $t-$t7 8-15 temporaries $s-$s7 16-23 saved $t8-$t9 24-25 more temporaries $gp 28 global pointer $sp 29 stack pointer $fp 3 frame pointer $ra 31 return address Register 1 ($at) reserved for assembler, 26-27 for operating system Computer Architecture CS-3511-2 24

Constants C code: x = x + 5; y = y + 1; z = z - 15; Some constants are loaded from memory to registers. Some hard-wired to registers ( $zero) MIPS Instructions: addi $29, $29, 4 slti $8, $18, 1 Design Principle 5: Make the common case fast. Computer Architecture CS-3511-2 25

Let s summarize MIPS simple instructions all 32 bits wide very structured, no unnecessary baggage only three instruction formats R I J op rs rt rd shamt funct op rs rt 16 bit address op 26 bit address - rely on compiler to achieve performance Computer Architecture CS-3511-2 26

Let s summarize Branches and Jumps Instructions: bne $t4,$t5,label beq $t4,$t5,label j Label Next instruction is at Label if $t4 $t5 Next instruction is at Label if $t4 = $t5 Next instruction is at Label Formats: op rs rt 16 bit address op 26 bit address Computer Architecture CS-3511-2 27

Let s summarize MIPS operands Name Example Comments $s-$s7, $t-$t9, $zero, Fast locations for data. In MIPS, data must be in registers to perform 32 registers $a-$a3, $v-$v1, $gp, arithmetic. MIPS register $zero alw ays equals. Register $at is $fp, $sp, $ra, $at reserved for the assembler to handle large constants. Memory[], Accessed only by data transfer instructions. MIPS uses byte addresses, so 2 3 memory Memory[4],..., sequential w ords differ by 4. Memory holds data structures, such as arrays, words Memory[4294967292] and spilled registers MIPS assembly language Category Instruction Example Meaning Comments add add $s1, $s2, $s3 $s1 = $s2 + $s3 Three operands; data in registers Arithmetic subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three operands; data in registers add immediate addi $s1, $s2, 1 $s1 = $s2 + 1 Used to add constants load w ord lw $s1, 1($s2) $s1 = Memory[$s2 + 1]Word from memory to register store w ord sw $s1, 1($s2) Memory[$s2 + 1] = $s1 Word from register to memory Data transfer load byte lb $s1, 1($s2) $s1 = Memory[$s2 + 1]Byte from memory to register store byte sb $s1, 1($s2) Memory[$s2 + 1] = $s1 Byte from register to memory branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to Equal test and branch L branch on not equal bne $s1, $s2, 25 if ($s1!= $s2) go to Conditional L branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; else $s1 = set less than immediate slti $s1, $s2, 1 if ($s2 < 1) $s1 = 1; else $s1 = Not equal test and Branch Compare less than; for beq, bne Compare less than constant Computer Architecture CS-3511-2 28

addi $v, $zero lw $v1, ($a) sw $v1, ($a1) addi $a, $a, 4 addi $a1, $a1, 4 beq $v1, $zero, loop op rs rt rd addr/ funct shamt 8 2 35 4 3 43 5 3 8 5 5 4 8 6 6 4 4 3 L/4 Computer Architecture CS-3511-2 29