Lecture 7: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Winter 2014 Diba Mirza Dept. of Computer Science and Engineering.

Slides:



Advertisements
Similar presentations
RAM (cont.) 220 bytes of RAM (1 Mega-byte) 20 bits of address Address
Advertisements

Instruction Set Design
Chapter 8: Central Processing Unit
Instructor: Tor Aamodt
RISC / CISC Architecture By: Ramtin Raji Kermani Ramtin Raji Kermani Rayan Arasteh Rayan Arasteh An Introduction to Professor: Mr. Khayami Mr. Khayami.
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review
CS 61C L06 MIPS Intro (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #6: Intro to MIPS
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
CIS 314: Introduction to MIPS Assembly Language: Arithmetic Fall 2005 I´ve been getting this a lot lately So, what are you teaching this term? Computer.
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
Choice for the rest of the semester New Plan –assembler and machine language –Operating systems Process scheduling Memory management File system Optimization.
CPEN Digital System Design Chapter 10 – Instruction SET Architecture (ISA) © Logic and Computer Design Fundamentals, 4 rd Ed., Mano Prentice Hall.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
CS1104 Assembly Language: Part 1
11/11/05ELEC CISC (Complex Instruction Set Computer) Veeraraghavan Ramamurthy ELEC 6200 Computer Architecture and Design Fall 2005.
CIS 314 : Computer Organization Lecture 1 – Introduction.
CS 61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Topic 1: Introduction to Computers and Programming
RISC and CISC. Dec. 2008/Dec. and RISC versus CISC The world of microprocessors and CPUs can be divided into two parts:
1 CS/COE0447 Computer Organization & Assembly Language Pre-Chapter 2.
1 Layers of Computer Science, ISA and uArch Alexander Titov 20 September 2014.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Computer Architecture ECE 4801 Berk Sunar Erkay Savas.
Natawut NupairojAssembly Language1 Introduction to Assembly Programming.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
COMP3221 lec04--prog-model.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Programmer’s Model of Microprocessors
Computer Organization and Design Computer Abstractions and Technology
CS35101 Computer Architecture Spring 2006 Week 1 Slides adapted from: Mary Jane Irwin ( Course url:
Chapter 2 Instructions: Language of the Computer Part I.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 2 Computer Organization.
ISA's, Compilers, and Assembly
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
The Processor & its components. The CPU The brain. Performs all major calculations. Controls and manages the operations of other components of the computer.
1 TM 1 Embedded Systems Lab./Honam University ARM Microprocessor Programming Model.
Instruction Set Architectures. Our Progress Done with levels 0 and 1 Seen multiple examples of level 2 Ready for ISA general principles.
Hello world !!! ASCII representation of hello.c.
Operating Systems A Biswas, Dept. of Information Technology.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
Addressing modes, memory architecture, interrupt and exception handling, and external I/O. An ISA includes a specification of the set of opcodes (machine.
Computers’ Basic Organization
Programs, Instructions, and Registers
DDC 2223 SYSTEM SOFTWARE DDC2223 SYSTEM SOFTWARE.
Assembly language.
Lecture 6: Assembly Programs
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
ISA's, Compilers, and Assembly
Microprocessor Systems Design I
Overview Introduction General Register Organization Stack Organization
Instruction Set Architectures
Lecture 4: MIPS Instruction Set
Lecture 7: Examples, MARS, Arithmetic
CS/COE0447 Computer Organization & Assembly Language
August 29 New address for Fang-Yi
Introduction to Microprocessor Programming
Introduction to Computer Systems
Instructions in Machine Language
COMS 361 Computer Organization
January 16 The books are here. Assignment 1 now due Thursday 18 Jan.
CPU Structure CPU must:
CS334: MIPS language _Mars simulator Lab 2_1
Lecture 4: Instruction Set Design/Pipelining
Chapter 4 The Von Neumann Model
Presentation transcript:

Lecture 7: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Winter 2014 Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego

Outline 1. Steps in program translation 2. Hardware/Software Interface Preliminaries 1. Instruction Set Architecture 1. General ISA Design (Architecture) 2. Architecture vs. Micro architecture 3. Different types of ISA: RISC vs CISC 2. Assembly programmer’s view of the system 1. Registers: Special and general purpose 2. Assembly and machine code (program translation detail) 3. Layout of ARM instructions in memory 3. Steps in program execution 4. Basic Types of ARM Assembly Instructions

Steps in program translation Program in C Helloworld.c Program in C Helloworld.c Code Time Program: Text file stored on computers hard disk or some secondary storage Compile Time Compiler Hardware Executable: Program in machine code +Data in binary Run Time

Compile time: What does gcc do? % gcc hello.c hello.c gcc a.out 4 “Source” Program in C #include void func1(int a, char *b) { if(a > 0) { *b = ‘a’; } } int main() {….. func1(); printf(“\abc”); } “Executable”: Equivalent program in machine language

Steps in gcc  The translation is actually done in a number of steps hello.c a.out 5 gcc hello.s Assembler(as) Linker (ld) hello.o Compiler (cpp) Compiler (cpp)

Steps in gcc  Ask compiler to show temporary files: % gcc –S hello.c (gives hello.s – assembly code) % gcc –c hello.c (gives hello.o – object module) % gcc –o prog_hello hello.c (gives prog_hello.o - named executable) hello.c a.out 6 gcc hello.s as cpp cc1 ld hello.o

Include code written by others  Code written by others (libraries) can be included  ld (linkage editor) merges one or more object files with the relevant libraries to produce a single executable hello.c a.out 7 gcc hello.s as cpp cc1 ld Library files e.g. math.o: the math library hello.o

Assembly Language A. Is the binary representation of a program. B. A symbolic representation of machine instructions C. A set of instructions that the machine can directly execute 8

Machine vs Assembly Language  Machine Language: A particular set of instructions that the CPU can directly execute – but these are ones and zeros  Assembly language is a symbolic version of the equivalent machine language  each statement (called an Instruction), executes exactly one of a short list of simple commands  Unlike in C (and most other High Level Languages), each line of assembly code contains at most 1 instruction  Instructions are related to operations (e.g. =, +, -, *) in C or Java

Steps in program translation Program in C Code Time Compile Time Compiler Assembler Instruction Set Architecture Hardware What makes programs run fast? 1.Algorithm 2.Compiler Translation to Machine code 3.ISA and hardware implementation

What is the Instruction Set Architecture? 11 Agreed-upon interface between all the software that runs on the machine and the hardware that executes it Primitive set of instructions a particular CPU implements I/O systemProcessor Memory Compiler Operating System Application Digital Design Circuit Design Instruction Set Architecture

General ISA Design Aspects 12 1.Everything about h/w that is visible to the s/w and can be manipulated by it via basic machine instructions. Example: Registers: How many? What size? Memory: How to access contents? 2.The set of basic machine instructions: A.What they are B.How they change the system state C.How they are encoded in binary CPU Bank of registers: Small and fast storage location Memory

Is the ISA different for different CPUs?  Different CPUs implement different sets of instructions.  Examples: ARM, Intel x86, IBM/Motorola PowerPC (Macintosh), MIPS, Inter IA32 …  Two styles of CPU design:  RISC (Reduced Instruction Set Computing)  CISC (Complex Instruction Set Computing)

RISC versus CISC (Historically)  Complex Instruction Set Computing e.g x86  Larger instruction set  More complicated instructions built into hardware  Variable length  Multiple clock cycles per instruction  Reduced Instruction Set Computing e.g. ARM  Small, highly optimized set of instructions  Memory accesses are specific instructions  One instruction per clock cycle  Instructions are of the same size and fixed format

A = A*B RISC LOAD A, eax LOAD B, ebx PROD eax, ebx STORE ebx, A C ISC MULT B, A

RISC vs CISC RISC  More work for compiler  More RAM used to store instructions  Easier to debug: more reliable processors  Easier to optimize  One clock cycle per instruction CISC Less work for compiler Fewer instructions to store Harder to maintain and debug

High level Language to AssemblyAssembly to Machine Language AOne-to-ManyMany-to-Many B One-to-One COne-to-ManyOne-to-One D For a program written in a high-level-language, the conversion from ____ to _____ will be __________ for different target processors

Translations  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, binary) code (for MIPS) C compilerassembler one-to-many one-to-one

Architecture vs Micro-architecture Architecture:  Parts of processor design needed to write programs in assembly  What is visible to s/w E.g Number of registers Micro-Architecture:  Detail of how architecture is implemented E.g Core frequency of the processor Aside: Processor Speed: Intel Core i7: 1.8 GHz 1.8 billion cycles per second Each instruction takes some number of cycles

The Assembly Programmer’s View of the machine  Registers: (Very) Small amount of memory inside the CPU  Each ARM register is 32 bits wide  Groups of 32 bits called a word in ARM Registers CPU Memory Stack Address Data Instructions Data

r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r15 (pc) cpsr r13 (sp) r14 (lr) The ARM Register Set General Purpose Registers Special Purpose Registers

Assembly Variables: Registers  Unlike HLL like C or Java, assembly cannot use variables  Why not? Keep Hardware Simple  Data is put into a register before it is used for arithmetic, tested, etc.  Manipulated data is then stored back in main memory.  Benefit: Since registers are directly in hardware, they are very fast

C, Java Variables vs. Registers  In C (and most High Level Languages) variables declared first and given a type  Example: int fahr, celsius; char a, b, c, d, e;  Each variable can ONLY represent a value of the type it was declared as (cannot mix and match int and char variables).  In Assembly Language, the registers have no type; operation determines how register contents are treated

Which one of the following is an optimization that is typically done by ARM compilers? A. Put the address of frequently used data in registers B. Put the value of frequently used data in registers C. Put as much data as possible in the registers D. Put as few program data in the registers E. Registers are not available to the programmer/compiler – they are only used internally by the processor to fetch and decode instructions

Layout of instructions in memory swap (int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } 0x4000 Swap: mov r2, r5 0x4004 add r4, r2, #1 0x4008 ldr r10, [r6,r2] 0x400c ldr r11, [r6,r4] 0x4010 mov r1, r10 0x4014 str r11,[r6,r2] 0x4018 str r1, [r6,r4] 0x401c bx lr

Machine Instructions A. Can be thought of as numbers. B. Are commands the computer performs. C. Were what people originally wrote programs using. D. All of the above. 26

Machine Instructions A. Can be thought of as numbers. B. Are commands the computer performs. C. Were what people originally wrote programs using. D. All of the above. 27

Steps in program execution PC:0x4000 CPU Memory Stack Instructions Data 0x4000 Swap: mov r2, r5 0x4004 add r4, r2, #1 0x4008 ldr r10, [r6,r2] 0x400c ldr r11, [r6,r4] 0x4010 mov r1, r10 0x4014 str r11,[r6,r2] 0x4018 str r1, [r6,r4] 0x401c bx lr

Assembly Language A. Is in binary. B. Allows languages to be designed for their specific uses. C. Has one line for every machine language instruction. 29

Basic Types of Instructions 1. Arithmetic: Only processor and registers involved 1. compute the sum (or difference) of two registers, store the result in a register 2. move the contents of one register to another 2. Data Transfer Instructions: Interacts with memory 1. load a word from memory into a register 2. store the contents of a register into a memory word 3. Control Transfer Instructions: Change flow of execution 1. jump to another instruction 2. conditional jump (e.g., branch if registeri == 0) 3. jump to a subroutine

31 High Level Language Program Assembly Language Program Compiler Machine Interpretation Machine Language Program Assembler temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; How to Speak Computer

32 High Level Language Program Assembly Language Program Compiler lw$15,0($2) lw$16,4($2) sw$16,0($2) sw$15,4($2) Machine Interpretation Machine Language Program Assembler temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;

How to Speak Computer 33 High Level Language Program Assembly Language Program Compiler lw$15,0($2) lw$16,4($2) sw$16,0($2) sw$15,4($2) Machine Interpretation Machine Language Program Assembler temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;

How to Speak Computer 34 High Level Language Program Assembly Language Program Compiler lw$15,0($2) lw$16,4($2) sw$16,0($2) sw$15,4($2) Machine Interpretation Machine Language Program Assembler temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;