CSE331 W02.1Irwin Fall 2001 PSU Computer Architecture Discussion Lecture # 2 MIPS Programming.

Slides:



Advertisements
Similar presentations
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Advertisements

Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
©UCB CS 161 Lecture 4 Prof. L.N. Bhuyan
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
Chapter 2.
Procedure call frame: Hold values passed to a procedure as arguments
331 W08.1Spring :332:331 Computer Architecture and Assembly Language Spring 2006 Week 8: Datapath Design [Adapted from Dave Patterson’s UCB CS152.
COM181 Computer Hardware Lecture 4: The MIPs CPU
CSE331 W02.1Irwin&Li 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Adaptado a DSD. R. Pereira Section 1: Mary Jane Irwin (
Instructions Set Bo Cheng Instruction Set Design An Instruction Set provides a functional description of a processor. It is the visible.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
331 W02.1Spring 05 Announcements  HW1 is due on this Friday  Appendix A (on CD) is very helpful to HW1.
1 CSE SUNY New Paltz Chapter 3 Machine Language Instructions.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
The Processor 2 Andreas Klappenecker CPSC321 Computer Architecture.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
331 W02.1Fall 2003 Announcements  HW1 is due on this Friday (Sept 12 th )  Appendix A is very helpful to HW1. Check out system calls on Page A-48. 
ECE 4436ECE 5367 ISA I. ECE 4436ECE 5367 CPU = Seconds= Instructions x Cycles x Seconds Time Program Program Instruction Cycle CPU = Seconds= Instructions.
331 Practice Exam.1Fall 2003 Naming Conventions for Registers 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
Some material taken from Assembly Language for x86 Processors by Kip Irvine © Pearson Education, 2010 Slides revised 2/2/2014 by Patrick Kelley.
Computer Engineering IntroLab1 page 1 Beginners explanation on how a processor works! The labs will teach you the truth.
08/08/ COM181 Computer Hardware Lecture 4: The MIPs CPU Ian McCrumRoom 5B18, Tel: voice mail.
1 CS/EE 362 Hardware Fundamentals Lecture 10 (Chapter 3: Hennessy and Patterson) Winter Quarter 1998 Chris Myers.
1 Computer Architecture COSC 3430 Lecture 3: Instructions.
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
Computer Architecture CSE 3322 Lecture 2 NO CLASS MON Sept 1 Course WEB SITE crystal.uta.edu/~jpatters.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture.
Digital Systems Design L02 MIPS ISA Review.1 Digital Systems Design Lecture 02: MIPS ISA Review Adapted from Mary Jane Irwin ( )
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Computer Organization Rabie A. Ramadan Lecture 3.
EE472 – Spring 2007P. Chiang, with Slide Help from C. Kozyrakis (Stanford) ECE472 Computer Architecture Lecture #3—Oct. 2, 2007 Patrick Chiang TA: Kang-Min.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Computer Organization Instructions Language of The Computer (MIPS) 2.
CPE 232 MIPS ISA1 CPE 232 Computer Organization MIPS ISA Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin ( which.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
Computer Organization Instructions Language of The Computer (MIPS) 2.
MIPS Lab CMPE 142 – Operating Systems. MIPS Simulator First Time Startup Setting Options.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
CSE 340 Computer Architecture Summer 2016 MIPS ISA Review.
CSE331 W02.1Irwin 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 2 Section 1: Mary Jane Irwin (
CS35101 Computer Architecture Spring 2006 Week 2.
COMPUTER ARCHITECTURE & OPERATIONS I
Instruction Set Architecture
Morgan Kaufmann Publishers
ELEN 468 Advanced Logic Design
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Computer Architecture & Operations I
CS170 Computer Organization and Architecture I
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
September 17 Test 1 pre(re)view Fang-Yi will demonstrate Spim
COMS 361 Computer Organization
COMS 361 Computer Organization
COMS 361 Computer Organization
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Presentation transcript:

CSE331 W02.1Irwin Fall 2001 PSU Computer Architecture Discussion Lecture # 2 MIPS Programming

CSE331 W02.2Irwin Fall 2001 PSU MIPS Arithmetic Instruction  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2  Each arithmetic instruction performs only one operation  Each arithmetic instruction specifies exactly three operands destination  source1 op source2  Those operands are contained in the datapath’s register file ( $t0, $s1,$s2 )  Operand order is fixed (destination first)

CSE331 W02.3Irwin Fall 2001 PSU MIPS Arithmetic Instruction  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2  Each arithmetic instruction performs only one operation  Each arithmetic instruction specifies exactly three operands destination  source1 op source2  Those operands are contained in the datapath’s register file ( $t0, $s1,$s2 )  Operand order is fixed (destination first)

CSE331 W02.4Irwin Fall 2001 PSU Compiling More Complex Statements  Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d

CSE331 W02.5Irwin Fall 2001 PSU Compiling More Complex Statements  Assuming variable b is stored in register $s1, c is stored in $s2, and d is stored in $s3 and the result is to be left in $s0, what is the assembler equivalent to the C statement h = (b - c) + d sub$t0, $s1, $s2 add$s0, $t0, $s3

CSE331 W02.6Irwin Fall 2001 PSU Accessing Memory  MIPS has two basic data transfer instructions for accessing memory lw$t0, 4($s3) #load word from memory sw$t0, 8($s3) #store word to memory (assume $s3 holds )  The data transfer instruction must specify l where in memory to read from (load) or write to (store) – memory address l where in the register file to write to (load) or read from (store) – register destination (source)  The memory address is formed by summing the constant portion of the instruction and the contents of the second register

CSE331 W02.7Irwin Fall 2001 PSU Accessing Memory  MIPS has two basic data transfer instructions for accessing memory lw$t0, 4($s3) #load word from memory sw$t0, 8($s3) #store word to memory (assume $s3 holds )  The data transfer instruction must specify l where in memory to read from (load) or write to (store) – memory address l where in the register file to write to (load) or read from (store) – register destination (source)  The memory address is formed by summing the constant portion of the instruction and the contents of the second register 28 32

CSE331 W02.8Irwin Fall 2001 PSU  Memory is viewed as a large, single-dimension array, with an address  A memory address is an index into the array Processor – Memory Interconnections Processor Memory 32 bits ? locations read addr/ write addr read data write data

CSE331 W02.9Irwin Fall 2001 PSU Compiling with Loads and Stores  Assuming variable b is stored in $s2 and that the base address of array A is in $s3, what is the MIPS assembly code for the C statement A[8] = A[2] - b $s3 $s3 +4 $s3 +8 $s A[2] A[3]... A[1] A[0]

CSE331 W02.10Irwin Fall 2001 PSU Compiling with Loads and Stores  Assuming variable b is stored in $s2 and that the base address of array A is in $s3, what is the MIPS assembly code for the C statement A[8] = A[2] - b $s3 $s3 +4 $s3 +8 $s A[2] A[3]... A[1] A[0] lw$t0, 8($s3) sub$t0, $t0, $s2 sw$t0, 32($s3)

CSE331 W02.11Irwin Fall 2001 PSU MIPS Instructions, so far CategoryInstrOp CodeExampleMeaning Arithmetic (R format) add0 and 32add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 and 34sub $s1, $s2, $s3$s1 = $s2 - $s3 Data transfer (I format) load word35lw $s1, 100($s2)$s1 = Memory($s2+100) store word43sw $s1, 100($s2)Memory($s2+100) = $s1

CSE331 W02.12Irwin Fall 2001 PSU 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function results 4$a0arguments 5$a1 6$a2 7$a3 8$t0temporary: caller saves...(callee can clobber) 15$t7 Review: Naming Conventions for Registers 16$s0callee saves... (caller can clobber) 23$s7 24$t8 temporary (cont’d) 25$t9 26$k0reserved for OS kernel 27$k1 28$gppointer to global area 29$spstack pointer 30$fpframe pointer 31$rareturn address (Hdware)

CSE331 W02.13Irwin Fall 2001 PSU [R] format and [I] format

CSE331 W02.14Irwin Fall 2001 PSU  Instructions, like registers and words of data, are also 32 bits long Example: add $t0, $s1, $s2 registers have numbers $t0=$8, $s1=$17, $s2=$18  Instruction Format: Machine Language - Arithmetic Instruction op rs rt rd shamt funct

CSE331 W02.15Irwin Fall 2001 PSU  Instructions, like registers and words of data, are also 32 bits long Example: add $t0, $s1, $s2 registers have numbers $t0=$8, $s1=$17, $s2=$18  Instruction Format: Machine Language - Arithmetic Instruction op rs rt rd shamt funct

CSE331 W02.16Irwin Fall 2001 PSU MIPS Instruction Fields  op  rs  rt  rd  shamt  funct op rs rt rd shamt funct 6 bits5 bits 6 bits= 32 bits

CSE331 W02.17Irwin Fall 2001 PSU MIPS Instruction Fields  op  rs  rt  rd  shamt  funct op rs rt rd shamt funct 6 bits5 bits 6 bits= 32 bits opcode indicating operation to be performed address of the first register source operand address of the second register source operand the register destination address shift amount (for shift instructions) function code that selects the specific variant of the operation specified in the opcode field

CSE331 W02.18Irwin Fall 2001 PSU  Consider the load-word and store-word instructions l Good design demands a compromise  Introduce a new type of instruction format l I-type for data transfer instructions l previous format was R-type for register  Example: lw $t0, 24($s2) Machine Language - Load Instruction op rs rt 16 bit number

CSE331 W02.19Irwin Fall 2001 PSU  Consider the load-word and store-word instructions, l What would the regularity principle have us do? l New principle: Good design demands a compromise  Introduce a new type of instruction format l I-type for data transfer instructions l previous format was R-type for register  Example: lw $t0, 24($s2) Machine Language - Load Instruction op rs rt 16 bit number

CSE331 W02.20Irwin Fall 2001 PSU  Example: sw $t0, 24($s2)  A 16-bit address means access is limited to memory locations within a region of  2 13 or 8,192 words (  2 15 or 32,768 bytes) of the address in the base register $s2 Machine Language - Store Instruction op rs rt 16 bit number

CSE331 W02.21Irwin Fall 2001 PSU  Example: sw $t0, 24($s2)  A 16-bit address means access is limited to memory locations within a region of  2 13 or 8,192 words (  2 15 or 32,768 bytes) of the address in the base register $s2 Machine Language - Store Instruction op rs rt 16 bit number

CSE331 W02.22Irwin Fall 2001 PSU Assembling Code  Remember the assembler code we compiled last lecture for the C statement A[8] = A[2] - b lw$t0, 8($s3)#load A[2] into $t0 sub$t0, $t0, $s2#subtract b from A[2] sw$t0, 32($s3)#store result in A[8] Assemble the MIPS object code for these three instructions

CSE331 W02.23Irwin Fall 2001 PSU Assembling Code  Remember the assembler code we compiled last lecture for the C statement A[8] = A[2] - b lw$t0, 8($s3)#load A[2] into $t0 sub$t0, $t0, $s2#subtract b from A[2] sw$t0, 32($s3)#store result in A[8] Assemble the MIPS code for these three instructions 35 lw sw sub

CSE331 W02.24Irwin Fall 2001 PSU Beyond Numbers  Most computers use 8-bit bytes to represent characters with the American Std Code for Info Interchange (ASCII) ASCIICharASCIICharASCIICharASCIICharASCIICharASCIIChar 133!49165A97a113q 234“50266B98b114r 335#51367C99c115s 4EOT36$52468D100d116t 537%53569E101e117u 6ACK38&54670F102f118v 739‘55771G103g119w 8bksp40(56872H104h120x 9tab41)57973I105i121y 10LF42*58:74J106j122z ;75K107k123{ 12FF44,60<76L108l124| 1547/63?79O111o127DEL

CSE331 W02.25Irwin Fall 2001 PSU Book Exercises  Book exercises solved: 2,3,4,6,13,20  and some exercises for R & I format