CS/COE1541: Introduction to Computer Architecture

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

Chapter 2: Instructions:

CS222: MIPS Instruction Set

Instruction Set Architecture. "Speaking with the computer"

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

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

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

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

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

Chapter 2. Instruction Set Architecture (ISA)

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

Course Administration

EEC 581 Computer Architecture Lecture 1 Review MIPS

CS3350B Computer Architecture MIPS Introduction

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

CS3350B Computer Architecture

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

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

EE 361 University of Hawaii Fall

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

Communicating with People (2.8)

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

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format 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

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

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

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

MIPS%Assembly% E155%

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

Computer Architecture. The Language of the Machine

Computer Architecture. MIPS Instruction Set Architecture

Instruction Set Architecture

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

Instructions: Language of the Computer

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

COMPUTER ORGANIZATION AND DESIGN

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

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

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

Control Instructions

Computer Organization MIPS ISA

ECE369. Chapter 2 ECE369

Chapter 2A Instructions: Language of the Computer

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

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

CENG3420 Lecture 03 Review

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

Lecture 3: Instruction Set Architecture

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Thomas Polzer Institut für Technische Informatik

Reduced Instruction Set Computer (RISC)

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

Computer Architecture

Reduced Instruction Set Computer (RISC)

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

ECE 30 Introduction to Computer Engineering

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

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

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

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

ECE 154A Introduction to. Fall 2012

Chapter 3. Instructions:

LECTURE 2: INSTRUCTIONS

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

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

Introduction. Datapath Basics

CS 4200/5200 Computer Architecture I

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

Instruction Set Architectures

Lecture 4: MIPS Instruction Set

ECE 486/586. Computer Architecture. Lecture # 7

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

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

Lectures 3-4: MIPS instructions

MIPS (SPIM) Assembler Syntax

CSSE 232 Computer Architecture I. I/O and Addressing

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

ECE232: Hardware Organization and Design

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

Instructions: Assembly Language

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Lecture 5: Procedure Calls

Chapter 4. The Processor

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:

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

Concocting an Instruction Set

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

Chapter 2. Instructions: Language of the Computer

Chapter 4. The Processor

Levels of Programming. Registers

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

Topic Notes: MIPS Instruction Set Architecture

Transcription:

CS/COE1541: Introduction to Computer Architecture Dept. of Computer Science University of Pittsburgh http://www.cs.pitt.edu/~melhem/courses/1541p/index.html 1 Computer Architecture? Application pull Operating systems Compiler Other applications, e.g., games Software layers architect Technology push Instruction Set Architecture Processor Organization VLSI Implementations Semiconductor technologies Architecture Microarchitecture Physical hardware 2

High level system architecture Input/output CPU(s) Interconnection cache control ALU memory Memory stores: Program code Data (static or dynamic) Execution stack registers Important registers: Program counter (PC) Instruction register (IR) General purpose registers 3 Chapter 1 Review: Computer Performance Response Time (latency) How long does it take for a task to be done? Throughput Rate of completing the tasks CPU execution time (our focus) doesn't count I/O or time spent running other programs Performance = 1 / Execution time Important architecture evaluation metrics Traditional metrics: TIME and COST More recent metrics: POWER and TEMPERATURE In this course, we will mainly talk about time 4

Clock Cycles (from Section 1.6) Instead of using execution time in seconds, we can use number of cycles Clock ticks separate different activities: cycle time = time between ticks = seconds per cycle time clock rate (frequency) = cycles per second (1 Hz. = 1 cycle/sec) EX: A 2 GHz. clock has a cycle time of 1 0.5 10 9 2 10 9 seconds. Time per program = cycles per program x time per cycle seconds program cycles program cycles Instruction seconds cycle Instructions program seconds cycle 5 Non-pipelined CPUs A B A A C Different instructions may take different number of cycles to execute (Why?) Cycles per instruction (CPI): Average number of cycles for executing an instruction (depends instruction mix) time Example: Assume that in a program: 20% of the instructions take one cycle (per instruction) to execute, 30% of the instructions take two cycles (per instruction) to execute and 50% of the instructions take three cycles (per instruction) to execute. The CPI for the program = 0.2 * 1 + 0.3 * 2 + 0.5 * 3 = 2.3 cycles/instruction 6

Machine performance Execution time = CPI # of instructions Cycle time Suppose we have two implementations of the same instruction set architecture (ISA). For some program, Machine A has a clock cycle time of 10 ns. and a CPI of 2.0 Machine B has a clock cycle time of 20 ns. and a CPI of 1.2 What machine is faster for this program (note that number of instructions in the program is the same)? Answer: Machine A is faster Definitions: # of instructions per cycle (IPC) = inverse of the CPI 7 MIPS ISA (from chapter 2) MIPS assumes 32 CPU registers ($0,, $31) All arithmetic instructions have 3 operands Operand order is fixed (destination first in assembly instruction) All operands of arithmetic operations are in registers Load and store instructions with simple memory addressing mechanism C code: A = B + C + D ; E = F - A ; MIPS code: add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0 The compiler t0, s1, s2, are symbolic names of registers (translated to the corresponding numbers by the assembler). 8

Register usage Conventions Name Register number Usage $zero 0 the constant value 0 $v0-$v1 2-3 values for results and expression evaluation $a0-$a3 4-7 arguments $t0-$t7 8-15 temporaries $s0-$s7 16-23 saved (correspond to program variables) $t8-$t9 24-25 more temporaries $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return address Note: registers 26 and 27 are reserved for kernel use. 9 Memory Organization Viewed as a large, single-dimension array of bytes. A memory address is an index into the array "Byte addressing" means that the index points to a byte of memory. A word in MIPS is 32 bits long or 4 bytes (will not consider 64-bit versions) 32 bits 0...0000000 = 0 0...0000001 = 1 0...0000010 = 2 0...0000011 = 3 0...0000100 = 4 0...0000101 = 5 0...0000110 = 6 32 bits 0...0000000 = 0 0...0000100 = 4 0...0001000 = 8 0...0001100 = 12... 32 bits of data 32 bits of data 32 bits of data 32 bits of data... Address space is 2 32 bytes with byte addresses from 0 to 2 32-1 2 30 words the address of a word is the address of its first byte the least 2 significant bits of a word address are always 00 Sometimes only 30 bits are used as a word address (drop the 00) 10

Load and Store Instructions A load/store memory address = content of a register + a constant C code: MIPS code: A[8] = h + A[8]; lw $t0, 32($s3) // load word add $t0, $s2, $t0 sw $t0, 32($s3) // store word $t0 $s2 $s3 registers Value of h Address Load from memory to register Store back Address Address+32 memory A[0] 8 words = 32 bytes A[8] Array A Can you modify the above example to add h to all the elements A[0],, A[8]? Need additional types of instructions? 11 Control instructions Decision making instructions alter the control flow, i.e., change the "next" instruction to be executed MIPS conditional branch instructions: beq $t0, $t1, label // branch if $t0 and $t1 contain identical data bne $t0, $t1, label // branch if $t0 and $t1 contain different data one may assign a label to any instruction in assembly language MIPS unconditional branch instruction: j label 12

C program down to numbers swap: muli $2, $5, 4 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } 00000000101000010 00000000000110000 10001100011000100 10001100111100100 10101100111100100 10101100011000100 00000011111000000 13 To summarize (short version of Figure 2.1): 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, 100 $s1 = $s2 + 100 Used to add constants load w ord lw $s1, 100($s2) $s1 = Memory[$s2 + 100] Word from memory to register store w ord sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100] Byte from memory to register store byte sb $s1, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memory load upper immediate lui $s1, 100 $s1 = 100 * 2 16 Loads constant in upper 16 bits branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to PC + 4 + 100 Equal test; PC-relative branch Conditional branch on not equal bne $s1, $s2, 25 if ($s1!= $s2) go to PC + 4 + 100 Not equal test; PC-relative branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; else $s1 = 0 Compare less than; for beq, bne set less than immediate slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; else $s1 = 0 Compare less than constant jump j 2500 go to 10000 in current segment Jump to target address Uncondi- jump register jr $ra go to $ra For switch, procedure return tional jump jump and link jal 2500 $ra = PC + 4; go to 10000 For procedure call Instruction operands: Some instructions use 3 registers Some instructions use 2 registers and a constant Some instructions use one register Some instructions use a constant 14

Machine Language instructions Instructions, like registers and data words, are also 32 bits long R-type instruction format: Example: add $t0, $s1, $s2 add $8, $17, $18 6 5 5 5 5 6 0 17 18 8 0 32 000000 10001 10010 01000 00000 100000 op rs rt rd shamt funct Source registers destination register Op-code extension I-type instruction format: Example: lw $t0, 36($s2) 6 5 5 16 35 18 8 36 100011 10010 01000 0000000000100100 op rs rt 16-bit number 15 Branch instructions (I-type) beq $4, $5, Label ===> put target address in PC if $4 == $5 The address stored in the 16-bit address of a branch instruction is the address of the target instruction relative to the next instruction (offset).z 6 5 5 16 beq rs rt 16 bit offset memory address L1: beq $4,$5,L2 sub...... 4 instructions...... L2: add......0100000...0100100...0110100 000100 00100 00101 0000000000000100 The next instruction (sub...) 4 instructions = (100) 2 words =(10000) 2 bytes The target instruction (add... ) 16

Jump instructions (J-type) In Jump instructions, address is relative to the 4 high order bits of PC+4 Memory is logically divided into 16 segments of 256 MB each. address in Jump instruction = offset from the start of the current segment memory 32-bit words 0000 000000000000000000000000000 Segment 0 26 bits 0111 000000000000000000000000000 0111 111111111111111111111111100 1000 000000000000000000000000000 Segment 7 L1:Jump L2 L2:... jump w w words 1111 111111111111111111111111100 Segment 15 Jump address = 0111 w 00 Current segment 26 bit relative address Byte address 17 Overview of MIPS only three instruction formats R op rs rt rd shamt funct I op rs rt 16 bit constant/offset J op 26 bit relative address Arithmetic and logic instructions use the R-type format Memory and branch instructions (lw, sw, beq, bne) use the I-type format Jump instructions use the J-type format Refer to section A.10 for complete specifications of MIPS instructions 18

MIPS Addressing modes (operands specification) 1. Immediate addressing op rs rt Immediate 2. Register addressing op rs rt rd... funct Registers Register 3. Base addressing op rs rt Address Memory Register + Byte Halfword Word 4. PC-relative addressing op rs rt Address Memory PC + Word 5. Pseudodirect addressing op Address Memory PC Word 19 x86 Addressing Modes (A contrast) 12 addressing modes available to compute the effective address Immediate (operand is in instruction as in MIPS) Register operand (operand in register as in MIPS) Displacement (the address of the operand is in the instruction similar to the jump instruction in MIPS (without the 4 PC bits) Relative (same as PC-relative in MIPS) Base + displacement (address = content of a base register + displacement ) similar to base addressing in MIPS Base (same as above with displacement = 0) Scaled index with displacement (use an index rather than a base register) Base with index and displacement (use two registers; base and index) Base scaled index with displacement (multiply the index by a scale) Actual address (linear address) = effective address + base address (the beginning of the current segment). Instructions other than load/store can access memory 20

x86 Address Calculation Displacement (16 bits) MIPS addressing 21 x86 Instruction Format (variable length instructions) 22