Lecture 3: Instruction Set Architecture

Similar documents
M2 Instruction Set Architecture

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS61C Machine Structures. Lecture 8 - Introduction to the MIPS Processor and Assembly Language. 9/14/2007 John Wawrzynek

I ve been getting this a lot lately So, what are you teaching this term? Computer Organization. Do you mean, like keeping your computer in place?

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points]

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

Lecture 7: Examples, MARS, Arithmetic

Lectures 3-4: MIPS instructions

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and RISC-V Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Raspberry Pi / ARM Assembly. OrgArch / Fall 2018

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

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Lecture 10: Program Development versus Execution Environment

Lecture 3: C Programm

Lecture 4: MIPS Instruction Set

Instruction Set Architectures

Lecture 4: Instruction Set Architecture

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

EC-801 Advanced Computer Architecture

CS/COE0447: Computer Organization

High Performance Computing Lecture 6. Matthew Jacob Indian Institute of Science

Instruction Set Architectures

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

ECE 154A Introduction to. Fall 2012

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

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

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture

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

High Performance Computing Lecture 7. Matthew Jacob Indian Institute of Science

Lecture 2: Number Representa2on

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

Communicating with People (2.8)

Lecture 2: C Programm

Computer Systems Lecture 9

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Lecture 4 (part 2): Data Transfer Instructions

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

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

CS 61c: Great Ideas in Computer Architecture

Instruction Set Architecture

Instruction Set Architecture

ECE 15B COMPUTER ORGANIZATION

Systems Architecture I

CSE 533: Advanced Computer Architectures Instructor: Gürhan Küçük. Instructions. Instructions cont d. Forecast. Basics. Basics

EC 413 Computer Organization

Systems I. Machine-Level Programming I: Introduction

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

CS 110 Computer Architecture Lecture 5: Intro to Assembly Language, MIPS Intro

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

CS61C : Machine Structures

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Today: Machine Programming I: Basics. Machine Level Programming I: Basics. Intel x86 Processors. Intel x86 Evolution: Milestones

Computer Architecture. Lecture 2 : Instructions

ECE369. Chapter 2 ECE369

CSE A215 Assembly Language Programming for Engineers

Computer Organization and Components

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

ISA: The Hardware Software Interface

ECE 486/586. Computer Architecture. Lecture # 7

CS/COE1541: Introduction to Computer Architecture

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

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

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

Review of instruction set architectures

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

CS429: Computer Organization and Architecture

RISC I from Berkeley. 44k Transistors 1Mhz 77mm^2

System calls and assembler

CS 61c: Great Ideas in Computer Architecture

Reminder: tutorials start next week!

Lecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines

Complex Instruction Sets

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423))

Processor Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Introduction Presentation A

Compilation, Disassembly, and Profiling (in Linux)

CSE Lecture In Class Example Handout

Code Generation. Lecture 30

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 1: Introduction

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

Outline. What Makes a Good ISA? Programmability. Implementability

Lecture 5: Instruction Set Architectures II. Take QUIZ 2 before 11:59pm today over Chapter 1 Quiz 1: 100% - 29; 80% - 25; 60% - 17; 40% - 3

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

Instruction Set Architecture

Instruction Set Architecture. "Speaking with the computer"

CISC 360 Instruction Set Architecture

CSE Lecture In Class Example Handout

CS 110 Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading)

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

Transcription:

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

1. Steps in program translation Outline 2. Hardware/Software Interface Preliminaries 1. Instruction Set Architecture 1. General ISA Design (Architecture) 2. 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

Compile time: What does gcc do? % gcc hello.c Source Program in C hello.c #include <stdio.h> void func1(int a, char *b) { if(a > 0) { *b = a ; } } int main() {.. func1(); printf( \abc ); } gcc Executable : Equivalent program in machine language a.out 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111! 3

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

Steps in gcc v 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) cpp hello.o ld hello.c gcc cc1 hello.s as a.out

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

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 7

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

What is an Instruction Set Architecture? 1. Everything about h/w that is visible to the s/w and can be manipulated by it via basic machine instructions (System state) CPU Memory Bank of registers: Small and fast storage location 10

What is an Instruction Set Architecture? 1. Everything about h/w that is visible to the s/w and can be manipulated by it via basic machine instructions (System state) 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 Memory Bank of registers: Small and fast storage location 11

Is the ISA different for different CPUs? Different CPUs implement different sets of instructions. Examples: ARM, Intel x86, IBM/Motorola PowerPC (Macintosh), MIPS, Intel 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 CISC LOAD A, eax! LOAD B, ebx! PROD eax, ebx! STORE ebx, A! MULT B, A!

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 lw $2, $4, $2 $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 one-to-many one-to-one C compiler assembler Machine (object, binary) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000...

The Assembly Programmer s View of the machine CPU Registers Address Data Instructions Memory Instructions Data Stack 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

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

ARM 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

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. 21

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. 22

Steps in program execution 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 Instructions Data PC:0x4000 CPU Stack Memory

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

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

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