ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
Branches Two branch instructions:
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Chapter 2 Instructions: Language of the Computer
CMPT 334 Computer Organization Chapter 2 Instructions: Language of the Computer [Adapted from Computer Organization and Design 5 th Edition, Patterson.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 4 - Instruction.
EECC550 - Shaaban #1 Lec # 2 Winter Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
CPSC CPSC 3615 Computer Architecture Chapter 3 Instructions and Addressing (Text Book: Chapter 5)
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
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.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
EECC550 - Shaaban #1 Lec # 2 Winter Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions.
Feb 18, 2009 Lecture 4-1 instruction set architecture (Part II of [Parhami]) MIPS assembly language instructions MIPS assembly programming.
MIPS Instruction Set Advantages
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Memory and Addressing How and Where Information is Stored.
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MS108 Computer System I Lecture 3 ISA Prof. Xiaoyao Liang 2015/3/13 1.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 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.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization Instruction Sets: MIPS Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann Publishers.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
1  1998 Morgan Kaufmann Publishers Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS Instruction Set Advantages
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
COMS 361 Computer Organization
Presentation transcript:

ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly Instructions Maciej Ciesielski

ECE 232 L5 Assembl.2 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Outline °Classes of instructions, formats R-type (register-register) I-type (immediate) J-type (jump) °MIPS assembly instructions Register access – operand(s) in registers Constant operands (immediate) Array access - operand in memory A[k] Making decisions (if then else) Branching further away °Pseudo instructions

ECE 232 L5 Assembl.3 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers MIPS R3000 Instruction Set Architecture °Instruction Categories Load/Store Computational Jump and Branch Floating Point -coprocessor Memory Management Special R0 - R31 PC HI LO 3 Instruction formats: all 32-bit wide Registers OPrs rt rdshftfunct R-type OPrs rt immediate I-type OP jump target J-type

ECE 232 L5 Assembl.4 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Register Instructions OPrs rt rdshftfunct R-type °Assume: g, h, i, j are stored in registers $s1 - $s4. Result f to be stored in $s0. °Compile: f = (g + h) – (i + j) into MIPS instructions: add $t0, $s1, $s2# register $t0  (g+h) add $t1, $s3, $s4# $t1  (i + j) sub $s0, $t0, $t1# $s0  $t0 - $t1

ECE 232 L5 Assembl.5 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Immediate format °Immediate = small constant stored in the instruction addi $sp, $sp, const# $sp  $sp + const OP const I-type rtrs °Range of constant operand: const  °Set on less-then, immediate slti $t0, $s2, const# $t0  1 if $s2 < const

ECE 232 L5 Assembl.6 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Operand in memory °Let A[ ] = array whose starting (base) address is in $s3; let variable h be associated with register $s2; °Compile: A[5] = h + A[8] into MIPS instructions: lw $t0, 32 ($s3) # $t0  A[8] add $t0, $s2, $t0 # $t0  h+$t0 sw $t0, 20 ($s3) # A[5]  $t0 OPrs rt immediate I-type 8*4 = 32 bytes (byte-addressable) $s3 5*4 =

ECE 232 L5 Assembl.7 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Array with variable index °A[ ] = array with base address in $s3; variables g, h, i associated with registers $s1, $s2, $s4 °Compile: g = h + A[i] into MIPS instructions: add $t1, $s4, $s4 # $t1  i+i = 2i add $t1, $t1, $t1 # $t1  2i+2i = 4i add $t1, $t1, $s3 # $t1  address of A[i] lw $t0, 0 ($t1) # $t0  A[i] add $s1, $s2, $t0 # $s1  h + A[i]

ECE 232 L5 Assembl.8 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers If statements °Let variables f, g, h, i, j be associated with $s0 - $s4 °Compile: if (i == j) go to L1; f = g + h; L1: f = f – i; into MIPS instructions: beq $s3, $s4, L1 # if i = j, go to L1 add $s0, $s1, $s2 # f = g + h (skipped if i=j) L1:sub $s0, $s0, $s3 # f = f – i (always executed)

ECE 232 L5 Assembl.9 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Jump instructions °Regular jump uses J-format j Label# jump to Label OP Label = jump target J-type °jr (jump on register address) uses R-format jr $t1# jump to A[($t1)] 26 OPrs 0 00funct R-type OP/funct = jr

ECE 232 L5 Assembl.10 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers If then else statements °Let variables f, g, h, i, j be associated with $s0 - $s4 °Compile: if (i == j) f = g + h; else f = g –h; into MIPS instructions: bne $s3, $s4, Else # if i  j, go to Else add $s0, $s1, $s2 # f = g + h (skipped if i  j) j Exit # go to Exit Else:sub $s0, $s1, $s2 # f = g – h (skipped if i = j) Exit: OP jump target J-type

ECE 232 L5 Assembl.11 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Pseudo-instructions °Let variables a, b be associated with $s0, $s1 °Compile: if (a < b) go to L into MIPS instructions: slt $t0, $s0, $s1# $t0  1 if $s0 < $s1 (a < b) bne $t0, $zero, L # if $t0  0, go to L °We can create pseudo-instruction: blt $s0, $s1, L °Special registers, useful in beq, bne, slt: °$zero is a special register, holds 0 °$at is another special register (1-bit) used in slt (set $at on less-then)

ECE 232 L5 Assembl.12 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Branching further away – pseudo-instruction °Consider a branch instruction beq $s0, $s1, L1# branch to L1 if $s0=$s1 °Change, to offer greater branching distance (  ): pseudo-instruction: beq $s0, $s1, Large bne $s0, $s1, L2# branch to L2 if $s0  $s1 j Large# unconditional jump to “Large” L2: OPrs rt immediate I-type small constant (  ) OP Large – jump target J-type 626

ECE 232 L5 Assembl.13 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Loading large numbers °Instruction lui: load upper immediate lui $t0, const# $t0 [31:16]  const 16 $to: const OP const I-type rt0

ECE 232 L5 Assembl.14 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers MIPS Addressing Modes/Instruction Formats immedoprsrt Immediate All instructions are 32-bit wide Base+index immedoprsrt register + Memory oprsrtrd register Register (direct ) PC-relative immedoprsrt PC Memory +

ECE 232 L5 Assembl.15 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers Operation Summary Support these simple instructions, since they will dominate the number of instructions executed: load, store, add, subtract, move register-register, and, shift, compare equal, compare not equal, branch, jump, call, return;