Instruction Set Architecture



Similar documents
Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Reduced Instruction Set Computer (RISC)

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Intel 8086 architecture

Review: MIPS Addressing Modes/Instruction Formats

Instruction Set Design

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Computer Organization and Architecture

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

CPU Organization and Assembly Language

Introduction to MIPS Assembly Programming

Instruction Set Architecture (ISA)

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

CHAPTER 7: The CPU and Memory

Instruction Set Architecture (ISA) Design. Classification Categories

2) Write in detail the issues in the design of code generator.

CSE 141 Introduction to Computer Architecture Summer Session I, Lecture 1 Introduction. Pramod V. Argade June 27, 2005

Central Processing Unit (CPU)

Translating C code to MIPS

Typy danych. Data types: Literals:

Computer organization

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

MICROPROCESSOR AND MICROCOMPUTER BASICS

8085 INSTRUCTION SET

LSN 2 Computer Processors

An Overview of Stack Architecture and the PSC 1000 Microprocessor

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

MACHINE ARCHITECTURE & LANGUAGE

An Introduction to the ARM 7 Architecture

Property of ISA vs. Uarch?

1 Classical Universal Computer 3

Instruction Set Architecture

PART B QUESTIONS AND ANSWERS UNIT I

Assembly Language Programming

More MIPS: Recursion. Computer Science 104 Lecture 9

UNIVERSITY OF CALIFORNIA, DAVIS Department of Electrical and Computer Engineering. EEC180B Lab 7: MISP Processor Design Spring 1995

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Computer Architecture Lecture 3: ISA Tradeoffs. Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

İSTANBUL AYDIN UNIVERSITY

In the Beginning The first ISA appears on the IBM System 360 In the good old days

Week 1 out-of-class notes, discussions and sample problems

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

(Refer Slide Time: 00:01:16 min)

Pipeline Hazards. Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. Based on the material prepared by Arvind and Krste Asanovic

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

How It All Works. Other M68000 Updates. Basic Control Signals. Basic Control Signals

THUMB Instruction Set

CS352H: Computer Systems Architecture

Computer Systems Architecture

PROBLEMS (Cap. 4 - Istruzioni macchina)

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

Microprocessor & Assembly Language

Chapter 7D The Java Virtual Machine

EC 362 Problem Set #2

Notes on Assembly Language

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

612 CHAPTER 11 PROCESSOR FAMILIES (Corrisponde al cap Famiglie di processori) PROBLEMS

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Chapter 2 Logic Gates and Introduction to Computer Architecture

MIPS Assembler and Simulator

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

Q. Consider a dynamic instruction execution (an execution trace, in other words) that consists of repeats of code in this pattern:

1 The Java Virtual Machine

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

WAR: Write After Read

Pipeline Hazards. Structure hazard Data hazard. ComputerArchitecture_PipelineHazard1

CPU Organisation and Operation

Solutions. Solution The values of the signals are as follows:

8051 MICROCONTROLLER COURSE

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

VLIW Processors. VLIW Processors

Z80 Microprocessors Z80 CPU. User Manual UM Copyright 2014 Zilog, Inc. All rights reserved.

Z80 Instruction Set. Z80 Assembly Language

A SystemC Transaction Level Model for the MIPS R3000 Processor

MIPS Assembly Code Layout

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

Where we are CS 4120 Introduction to Compilers Abstract Assembly Instruction selection mov e1 , e2 jmp e cmp e1 , e2 [jne je jgt ] l push e1 call e

CS:APP Chapter 4 Computer Architecture Instruction Set Architecture. CS:APP2e

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

OAMulator. Online One Address Machine emulator and OAMPL compiler.

Processor Architectures

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

picojava TM : A Hardware Implementation of the Java Virtual Machine

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Basic Computer Organization

Computer Architectures

Compilers I - Chapter 4: Generating Better Code

The Design of the Inferno Virtual Machine. Introduction

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

Computer Organization and Components

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997

Summary of the MARIE Assembly Language

Exception and Interrupt Handling in ARM

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

CHAPTER 4 MARIE: An Introduction to a Simple Computer

Transcription:

Instruction Set Architecture Consider x := y+z. (x, y, z are memory variables) 1-address instructions 2-address instructions LOAD y (r :=y) ADD y,z (y := y+z) ADD z (r:=r+z) MOVE x,y (x := y) STORE x (x:=r) 3-address instructions ADDx, y, z (x:= y+z) 0-address instructions (for stack machines) push pop PUSH y (on a stack) PUSH z (on a stack) ADD POP x

Points to Consider Special-purpose or general purpose? Word size and instruction size? [Now most instructions have 32-bits, and machines allow operation on 64-bit data operands] Data types? [Whatever the application demands] 0/1/2/3 address instructions, or a mix of them? [Most modern designs allow 3-address instructions, and pack them in a 32-bit frame] How many addressing modes, and which ones? [Whatever the application demands] Register or memory operands? [Register operands can be accessed faster, but you cannot have too many registers] Instruction formats and instruction encoding. [Modern designs have fewer formats and they are less clumsy]

Instruction Types BASIC INSTRUCTIONS Data Movement Arithmetic & Logical LOAD, STORE, MOVE ADD, SUB, AND, XOR, SHIFT Branch JUMP (unconditional) JZ, JNZ (conditional) Procedure Call Input Output Miscellaneous CALL, RETURN Memory-mapped I/O* NOP, EI (enable interrupt) SPECIAL INSTRUCTIONS Multimedia instructions (MMX) Many SIMD or vector instructions operate simultaneously on 8 bytes 4 half-words 2 words Digital Signal Processors include multiply-and-accumulate (MAC) to efficiently compute the dot-product of vectors.

Load Store Architecture Only LOAD and STORE instructions access the memory. All other instructions use register operands. Used in all RISC machines. If X,Y,Z are memory operands, then X:= Y+Z will be implemented as LOAD LOAD ADD r1, Y r2, Z r1, r2, r3 STORE r3, X Performance improves if the operand(s) can be kept in registers for most of the time. Registers are faster than memory. Register allocation problem.

Common Addressing Modes Op data type mode reg addr/data/offset opcode(o) reg (R) address (D) Mode immediate direct Register indirect Memory indirect Auto-increment meaning Operand = D Operand = M[D] Operand = M[R] Operand = M[M[D]] Operand = M[R] R = R + n (n=1 2 4 8) Auto-decrement R = R n (n = 1 2 4 8) Operand = M[R] Indexed Scale-index-base (SIB) PC-relative SP-relative Operand = M[R+D] Operand = M[s * R+D] Operand = M[PC+D] Operand = M[SP+D] (Note: R = content of register R) Question: Why so many addressing modes? Do we need all?

RISC or CISC? Reduced Instruction Set Computers have a small number of simple, frequently used instructions. Complex Instruction Set Computers include as many instructions as users might need to write efficient programs. Features CISC RISC Semantic Gap Low High Code Size Small Large, but RAMs are cheap! Cost High Low Speed Fast only if the compiler generates appropriate code Slower, but the problem is overcome using more registers and pipelining.

MIPS Architecture MIPS follows the RISC architecture. It has 32 registers r0-r31. Each register has 32-bits. The conventional use of these registers is as follows: register assembly name Comment r0 r1 r2-r3 r4-r7 r8-r15 r16-r23 r24-r25 r26-r27 r28 r29 r30 r31 $zero $at $v0-$v1 $a0-$a3 $t0-$t7 $s0-$s7 $t8-$t9 $k0-$k1 $gp $sp $fp $ra Always 0 Reserved for assembler Stores results Stores arguments Temporaries, not saved Contents saved for use later More temporaries, not saved Reserved by operating system Global pointer Stack pointer Frame pointer Return address

Example assembly language programs Example 1 f = g + h i Assume that f, g, h, i are assigned to $s0, $s1, $s2, $s3 add $t0, $s1, $s2 sub $s0, $t0, $s3 # register $t0 contains g + h # f = g + h i Example 2. g = h + A[8] Assume that g, h are in $s1, $s2. A is an array of words the elements are stored in consecutive locations of the memory. The base address is stored in $s3. lw t0, 32($s3) add $s1, $s2, $t0 # t0 gets A[8], 32= 4x8 # g = h + A[8]

0 200 Word 1 = 4 bytes Word 2 = 4 bytes Word 3 = 4 bytes 200 s3 t0 lw Word 8 = 4 bytes CPU MEMORY

Machine language representations Instruction add belongs to the R-type format. opcode rs rt rd shift amt function 6 5 5 5 5 6 src src dst add $s1, $s2, $t0 (s1 := s2 + t0) will be coded as 0 18 8 17 0 32 6 5 5 5 5 6 The function field is an extension of the opcode, and they together determine the operation. Note that sub has a similar format.

Instruction lw (load word) belongs to I-type format. opcode rs rt address 6 5 5 16 base dst offset lw $t0, 32($s3) will be coded as 35 19 8 32 6 5 5 16 Both lw and sw (store word) belong to I-format.

Making decisions if (i ==j) f = g + h; else f = g h Use bne = branch-nor-equal, beq = branch-equal, and j = jump Assume, f, g, h, are mapped into $s0, $s1, $s2, and i, j are mapped into $s3, $s4 bne $s3, $s4, Else add $s0, $s1, $s2 # goto Else when i=j # f = g + h j Exit # goto Exit Else: sub $s0, $s1, $s2 # f = g h Exit:

The program counter Every machine has a program counter (called PC) that points to the next instruction to be executed. 1028 Instruction 1 1032 Instruction 2 1028 1036 Instruction 3 PC Instruction 4 data CPU data MEMORY Ordinarily, PC is incremented by 4 after each instruction is executed. A branch instruction alters the flow of control by modifying the PC.

Compiling a while loop while (A[i] == k) i = i + j; array A Initially $s3, $s4, $s5 contains i, j, k respectively. Let $s6 store the base of the array A. Each element of A is a 32-bit word. Loop: add $t1, $s3, $s3 # $t1 = 2*i add $t1, $t1, $t1 # $t1 = 4*i add $t1, $t1, $s6 # $t1 contains address of A[i] lw $t0, 0($t1) add $s3, $s3, $s4 bne $t0, $s5, Exit j Loop # $t0 contains $A[i] # i = i + j # goto Exit if A[i] k # goto Loop Exit: <next instruction> Note the use of pointers.

Compiling a switch statement switch (k) { case 0: case 1: case 2: case 3: f = i + j; break; f = g + h; break; f = g h; break; f = I j; break; } Assume, $s0-$s5 contain f, g, h, i, j, k. Assume $t2 contains 4. slt $t3, $s5, $zero bne $t3, $zero, Exit slt $t3, $s5, $t2 beq $t3, $zero, Exit # if k<0 then $t3 = 1 else $t3=0 # if k<0 then Exit # if k<4 then $t3 = 1 else $t3=0 # if k 4 the Exit What next? Jump to the right case!

32-bit address L0 32-bit address L1 32-bit address L2 32-bit address L3 jumptable Base address of the jumptable register $t4 L0 L1 f = i + j J Exit f = g+h j Exit Exit MEMORY

Here is the remainder of the program; add $t1, $s5, $s5 add $t1, $t1, $t1 add $t1, $t1, $t4 lw $t0, 0($t1) jr $t0 L0: add $s0, $s3, $s4 J Exit L1: add $s0, $s1, $s2 J Exit L2: sub $s0, $s1, $s2 J Exit L3: sub $s0, $s3, $s4 Exit: <next instruction>