Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. MIPS Assembly

Similar documents
Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. MIPS Assembly

Computer Systems and Networks. ECPE 170 Jeff Shafer University of the Pacific. MIPS Assembly

CSEE 3827: Fundamentals of Computer Systems

Computer Systems and Networks

Computer Systems and Networks

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

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

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

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

CS3350B Computer Architecture MIPS Introduction

Topic Notes: MIPS Instruction Set Architecture

EC 413 Computer Organization

EE108B Lecture 2 MIPS Assembly Language I. Christos Kozyrakis Stanford University

Lecture 4: Instruction Set Architecture

Chapter 2A Instructions: Language of the Computer

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

MIPS Assembly Programming

Computer Model. What s in a computer? Processor Memory I/O devices (keyboard, mouse, LCD, video camera, speaker, disk, CD drive, )

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

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

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

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

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

Computer Architecture

RISC, CISC, and ISA Variations

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

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

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

Modern Instruc?on Sets

Chapter 2. Instructions:

Lecture 3 Machine Language. Instructions: Instruction Execution cycle. Speaking computer before voice recognition interfaces

IC220 SlideSet #2: Instructions (Chapter 2)

Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University. See P&H Appendix , and 2.21

Modern Instruc?on Sets

COE608: Computer Organization and Architecture

MIPS Instruction Set Architecture (1)

CS3350B Computer Architecture MIPS Instruction Representation

ECE 486/586. Computer Architecture. Lecture # 7

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?

CS3350B Computer Architecture

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

Review of instruction set architectures

Hardware Level Organization

Hakim Weatherspoon CS 3410 Computer Science Cornell University

MIPS History. ISA MIPS Registers

ECE260: Fundamentals of Computer Engineering

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

Computer Architecture. MIPS Instruction Set Architecture

Lecture #6 Intro MIPS; Load & Store

Instructions: Language of the Computer

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

Chapter 3. Instructions:

CENG3420 L03: Instruction Set Architecture

ECE232: Hardware Organization and Design

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

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

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

Instruction Set Architecture (ISA)

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

Instructions: Language of the Computer

Memory Hierarchy (Performance OpAmizaAon)

IT 252 Computer Organization and Architecture. Introduction. Chia-Chi Teng

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

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

ECE 154A Introduction to. Fall 2012

ECE232: Hardware Organization and Design

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Instruction Set Architecture. "Speaking with the computer"

Performance Op>miza>on

CSE : Introduction to Computer Architecture

Slide Set 1 (corrected)

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

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

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

Computer Systems Laboratory Sungkyunkwan University

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Alternate definition: Instruction Set Architecture (ISA) What is Computer Architecture? Computer Organization. Computer structure: Von Neumann model

Chapter 2: Instructions How we talk to the computer

378: Machine Organization and Assembly Language

URL: Offered by: Should already know: Will learn: 01 1 EE 4720 Computer Architecture

Chapter 13 Reduced Instruction Set Computers

CSCI 402: Computer Architectures

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

ECE369. Chapter 2 ECE369

MIPS (SPIM) Assembler Syntax

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

URL: Offered by: Should already know: Will learn: 01 1 EE 4720 Computer Architecture

CS3350B Computer Architecture MIPS Procedures and Compilation

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

Computer Architecture

Chapter 2: Instructions:

Chapter 2. Instruction Set Architecture (ISA)

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

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

CENG3420 Lecture 03 Review

Lecture #4: Computer Hardware (CPUs)

Transcription:

ECPE 170 Jeff Shafer University of the Pacific MIPS Assembly

2 Lab Schedule AcAviAes Assignments Due Today Sunday, Oct 28 th MIPS discussion Lab 6 due by midnight PracAce problems (paper & pencil) Next Tuesday / Thursday Lab 8 MIPS Using the QtSPIM simulator

3 Person of the Day John Cocke ì Computer architecture pioneer ì ì Father of RISC Architecture Developed IBM 801 processor, 1975-1980 ì Winner, ACM Turing Award, 1987 RISC = Reduced InstrucLon Set CompuLng Achieve higher performance with simple instrucaons that execute faster Computer Systems and Networks Fall 2012

4 Person of the Day John Hennessy Computer architecture pioneer Popularized RISC architecture in early 1980 s Founder of MIPS Computer Systems in 1984 Currently president of an obscure school: Stanford University

5 Class to Date Human Compiler Compiler Linker (C Code) (Assembly code) (Object file / binary code) (Executable program)

6 Class Now Human (Assembly code) Assembler (Object file / binary code) Linker (Executable Program)

7 MIPS

8 MIPS Overview Family of computer processors first introduced in 1981 Microprocessor without Interlocked Pipeline Stages Original acronym Now MIPS stands for nothing at all

9 MIPS Products Embedded devices Cisco/Linksys routers Cable boxes MIPS processor is buried inside System- on- a- Chip (SOC) Gaming / entertainment Nintendo 64 PlaystaAon 2, PSP Computers? Not so much anymore SGI / DEC / NEC workstaaons back in 1990 s

10 MIPS Design RISC What does this mean? Reduced InstrucAon Set CompuAng Simplified design for instrucaons Use more instrucaons to accomplish same task But each instrucaon runs much faster! 32 bits (originally) What does this mean? 1 word = 32 bits Size of data processed by an integer add instrucaon New(er) MIPS64 design is 64 bits, but we won t focus on that

11 MIPS Assembly Programming

12 Quotes Donald Knuth People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. Donald Knuth Remember this when we re learning MIPS assembly in Labs 8 and 9!

13 Why Learn Assembly Programming? Computer Science track Understand capabiliaes (and limitaaons) of physical machine Ability to opamize program performance (or funcaonality) at the assembly level if necessary Computer Engineer track Future courses (e.g. ECPE 173) will focus on processor design Start at the assembly programming level and move into hardware How does the processor implement the add instrucaon? How does the processor know what data to process?

14 Instruction Set Architecture InstrucLon Set Architecture (ISA) is the interface between hardware and sojware Specifies the format of processor instrucaons Specifies the format of memory addresses (and addressing modes) Specifies the primiave operaaons the processor can perform

15 Instruction Set Architecture ISA is the contract between the hardware designer and the assembly- level programmer Documented in a manual that can be hundreds or thousands of pages long Example: Intel 64 and IA- 32 Architectures Sojware Developers Manual hkp://www.intel.com/content/www/us/en/processors/ architectures- sojware- developer- manuals.html No joke the manual PDF from August 2012 is 3020 pages long!

16 Instruction Set Architecture Processor families share the same ISA Example ISAs: Intel x86 Intel / AMD x86-64 Intel Itanium ARM IBM PowerPC MIPS All completely different, in the way that C++, Java, Perl, and PHP are all different and yet learning one language makes learning the next one much easier

17 Why MIPS? Why choose MIPS? The MIPS ISA manual (volume 1, at least) is a svelte 108 pages! Extremely common ISA in textbooks Freely available simulator Common embedded processor Good building- block for other RISC- style processors Aligns with ECPE 173 course

18 Arithmetic Instructions AddiAon SubtracAon add <result>, <input1>, <input2> sub <result>, <input1>, <input2> OperaAon / Op code Operands

19 Task : Write Code Write MIPS assembly for f = (g+h) (i+j) add temp0, g, h add temp1, i, j sub f, temp0, temp1

20 CongratulaLons! You re now an assembly programming expert!

21 Data Sources Previous example was (just a lihle bit) fake We made up some variables: temp0, temp1, f, g, h, i, and j This is what you do when programming in C++ (or any high level language) Problem: You can t make up variables in assembly! (as least, not in this fashion)

22 Data Sources Where can we explicitly place data in assembly programming? 1. Registers CPU On the CPU itself Very close to ALU Tiny ALU Cache Memory Access Ame: 1 cycle 2. Memory Off- chip Large Access Ame: 100+ cycles

23 Aside Cache Review: Does the programmer explicitly manage the cache? Ans: No! The assembly programmer just reads/writes memory addresses Cache is managed automaacally in hardware Result: Memory appears to be faster than it really is

24 ECPE 71 From your knowledge of ECPE 71 (Digital Design), how would you construct a register? Flip Flops! (D Flip Flop shown)

25 ECPE 71 Group of Registers

26 Registers MIPS design: 32 integer registers, each holding 32 bits Word size = 32 bits Name Use $zero $s0-$s7 $t0-$t9 Constant value: ZERO Local variables Temporary results This is only 19 where are the rest of the 32? Reserved by convenlon for other uses We ll learn a few more later

27 Task : Write Code Write MIPS assembly using registers for: f = (g+h) (i+j) Map: $s0 = g $s1 = h $s2 = i $s3 = j $s4 = f Code: add $t0, $s0, $s1 add $t1, $s2, $s3 sub $s4, $t0, $t1

28 More Arithmetic Instructions Add Immediate addi <result>, <input1>, <constant> Register Register Can be a posiave or negaave number!

29 Task : Write Code Write MIPS assembly using registers for: f = g+20 Map: $s0 = f $s1 = g Code: addi $s0, $s1, 20

30 Memory Challenge: Limited supply of registers Physical limitaaon: We can t put more on the processor chip, and maintain their current speed Many elements compete for space in the CPU SoluAon: Store data in memory MIPS provides instrucaons that transfer data between memory and registers

31 Memory Fundamentals MIPS cannot directly manipulate data in memory! Data must be moved to a register first! (And results must be saved to a register when finished) Common design in RISC- style machines

32 Memory Fundamentals Yes, it s a pain to keep moving data between registers and memory. But consider it your molvalon to reduce the number of memory accesses. That will improve program performance!

33 Memory Fundamentals Four quesaons to ask when accessing memory: 1. What direclon do I want to copy data? (i.e. to memory, or from memory?) 2. What is the specific memory address? 3. What is the specific register name? (or number) 4. How much data do I want to move?

34 Memory Fundamental Operations Load Store Copy data from memory to register Copy data from register to memory Memory CPU Memory CPU

35 Memory Determining Address There are many ways to calculate the desired memory address These are called addressing modes We ll just learn one mode now: base + offset The base address could be HUGE! (32 bits) We ll place it in a register The offset is typically small We ll directly include it in the instrucaon as an immediate Base 0 1 Memory 2 3 Offset 4 MIPS notalon: offset(base)

36 Memory Register Name What is the name of the register to use as either the data desanaaon (for a load) or a data source (for a store)? Use the same register names previously learned

37 Memory - Data Transfer Size How much data do I want to load or store? A full word? (32 bits) A half word? (16 bits) A byte? (8 bits) We ll have a different instruclon for each quanlty of data No opaon to load an enare array!

38 Memory Data Transfer Instructions Load (copy from memory to register) Word: lw <reg>, <offset>(<base addr reg>) Byte: lb <reg>, <offset>(<base addr reg>) Store (copy from register to memory) Word: sw <reg>, <offset>(<base addr reg>) Byte: sb <reg>, <offset>(<base addr reg>) Register Memory LocaAon

39 Example What will this instruclon do? lw $s1, 20($s2) Load word copies from memory to register: Base address: stored in register $s2 Offset: 20 bytes DesAnaAon register: $s1 Amount of data transferred: 1 word (32 bits)

40 Task : Write Code Write MIPS assembly for: g = h + array[16] (Array of words. Can leave g and h in registers) Map: $s1 = g $s2 = h $s3 = base address of array Code: # Assume $s3 is already set lw $t0, 16($s3) add $s1, $s2, $t0

41 Memory Address Slight flaw in previous soluaon The programmer intended to load the 16 th array element Each element is 4 bytes (1 word) The offset is in bytes 16 * 4 = 64 Correct Code: # Assume $s3 is already set lw $t0, 64($s3) add $s1, $s2, $t0

42 Task : Write Code Write MIPS assembly for: array[12] = h + array[8] (Array of words. Assume h is in register) Map: $s2 = h $s3 = base address of array $t1 = temp Code: # Assume $s3 is already set lw $t0, 32($s3) add $t1, $s2, $t0 sw $t1, 48($s3)

43 Task : Write Code Write MIPS assembly for: g = h + array[i] (Array of words. Assume g, h, and i are in registers) Map: $s1 = g $s2 = h $s3 = base address of array $s4 = i Code: # "Multiply" i by 4 add $t1, $s4, $s4 add $t1, $t1, $t1 # Get addr of array[i] add $t1, $t1, $s3 # Load array[i] lw $t0, 0($t1) # Compute add add $s1, $s2, $t0 # x2 # x2 again

44 Aside Compiler When programming in C / C++, are your variables (int, float, char, ) stored in memory or in registers? Ans: It depends Compiler will choose where to place variables Registers: Loop counters, frequently accessed scalar values Memory: Arrays, infrequently accessed data values

45 Resources Resources on Website view Resources page MIPS InstrucLon Set (paraal guide) Resources available in Sakai site (under ECPE 170) HP_AppA.pdf Appendix A from famous Hennessy & Pakerson Computer OrganizaLon textbook Assemblers, Linkers, and the SPIM simulator StarAng on page 51 is an overview of the MIPS assembly commands! MIPS_Green_Sheet.pdf Cheat sheet for expert programmers MIPS commands, registers, memory convenaons,