Computer Organization 2015 - 2016 1. Instructions Language of The Computer (MIPS) 2.

Slides:



Advertisements
Similar presentations
MIPS Assembly Tutorial
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
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
CIS 314 Fall 2005 MIPS Datapath (Single Cycle and Multi-Cycle)
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Chapter 2 Instructions: Language of the Computer
Chapter 2 Instructions: Language of the Computer Part III.
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.
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.”
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
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.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
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.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 1 In-Class Lab Session (Lab 2)
Lecture 15: 10/24/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 3: MIPS Instruction Set I Topics: 1.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
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.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Organization & Programming Chapter 6 Single Datapath CPU Architecture.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
9/29: Lecture Topics Conditional branch instructions
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization Rabie A. Ramadan Lecture 3.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Computer Architecture CSE 3322 Lecture 4 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/10/09
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization Instructions Language of The Computer (MIPS) 2.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
10/1: Lecture Topics Conditional branch instructions –slides from 9/29 set Unconditional jump instructions Instruction encoding.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Computer Architecture & Operations I
MIPS Instruction Set Advantages
COMPUTER ARCHITECTURE & OPERATIONS I
Morgan Kaufmann Publishers
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
Computer Architecture & Operations I
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
CS170 Computer Organization and Architecture I
The University of Adelaide, School of Computer Science
MIPS coding.
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
MIPS Instruction Encoding
Datapath & Control MIPS
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
COMP541 Datapaths I Montek Singh Mar 18, 2010.
COMS 361 Computer Organization
COMS 361 Computer Organization
MIPS Assembly.
MIPS Coding Continued.
MIPS coding.
Presentation transcript:

Computer Organization

Instructions Language of The Computer (MIPS) 2

Exercise 1 Assuming A is an integer array with base in $s4 and that the compiler associates the integer variables g, i, and n with the registers $s1, $s2, and $s3, respectively What is the compiled MIPS assembly code for the following C code segment? i=0; while(i < n) { g = g + A[i]; i++; } 3

Exercise 1 Sol. add $s2, $zero, $zero# i = 0 while: slt $t0, $s2, $s3# test if i < n beq $t0, $zero, Exit sll $t1, $s2, 2 # $t1 = 4*i add $t1, $t1, $s4# $t1 has address of A[i] lw $t2, 0 ($t1)# $t2 = A[i] add $s1, $s1, $t2 addi $s2, $s2, 1# increment i j while Exit: 4

Decision Making Instructions (cont.) There are two ways to implement case/switch statements: – 1. Turn a switch statement into a chain of if-then-else statements in the high-level language and then into chained conditional jumps MIPS 2. Encode a table of addresses of alternative instruction sequences, called a jump address table ( Jump Table) 5

Exercise 2 Assume the six integer variables f through k correspond to the six registers $s0 through $s5 What is the compiled MIPS assembly code for the following C code segment? switch (k) { case 0: f = i + j; break; case 1: f = g + h; break; case 2: f = g -h; break; case 3: f = i -j; break; } 6

Exercise 2 Sol. Chain of if-else beq $s5,$zero, L0# if k=0 branch to L0 add $t0,$zero, $zero# $t0=0 addi $t0, $t0, 1# $t0=1 beq $s5, $t0, L1# if k=1 branch to L1 addi $t0, $t0, 1# $t0=2 beq $s5, $t0, L2# if k=2 branch to L2 addi $t0, $t0, 1# $t0=3 beq $s5, $t0, L3# if k=2 branch to L3 jExit 7

Exercise 2 Sol. Chain of if-else L0:add$s0,$s3, $s4# f = i + j jExit# break L1:add$$s0,$s1, $s2 # f = g + h jExit# break L2:sub$s0,$s1, $s2# f = g –h jExit# break L3:sub$s0,$s3, $s4# f = i –j jExit# break Exit: 8

Exercise 2 Sol. Jump Table the Jump Table is just an array of words containing addresses that correspond to labels in the code the program loads the appropriate entry from JumpTable into a register and then it jumps to the proper address using a jump register (jr) To access the JumpTable, assume that four sequential words in memory, starting at an address contained in register $t4, have addresses corresponding to the labels L0, L1, L2, and L3 9

Exercise 2 Sol. Jump Table slt$t3,$s5, $zero# test if k < 0 bne$t3,$zero, Exit# exit if k < 0 slti$t3,$s5, 4# test if k < 4 beq$t3,$zero, Exit # exit if k ≥4 sll$t1,$s5, 2# $t1 = 4*k add$t1,$t1, $t4# JumpTable[k] address jr$t1# jump register 10

Exercise 2 Sol. Jump Table L0:add$s0,$s3, $s4# f = i + j jExit# break L1:add$s0,$s1, $s2 # f = g + h jExit# break L2:sub$s0,$s1, $s2# f = g –h jExit# break L3:sub$s0,$s3, $s4# f = i –j jExit# break Exit: 11

Instruction Formats Register format: R-format Used by arithmetic and logical instructions Immediate format: I-format Used by data transfer instructions Used by instructions that have immediate operands Used by relative-address branching Jump format: J-format Used by absolute-jump instructions 12

Instruction Formats (cont.) 13

Instruction Formats (cont.) op: basic operation of the instruction, traditionally called opcode rs: the first register source operand rt: the second register source operand in R-format. This field sometimes specifies a destination register in I-format rd: the register destination operand that gets the operation result shamt: shift amount, used in shift instructions Funct: function code that selects the specific variant of the operation in the op field in R-format 14

15

Exercise 3 Show the real MIPS machine language version for the instruction represented symbolically as add $t0, $s1, $s2 Registers have numbers: $t0 = 8, $s1 = 17, $s2 = 18 16

Exercise 3 Sol. add $t0, $s1, $s2 $t0 = 8, $s1 = 17, $s2 = 18 17

Exercise 4 Show the real MIPS machine language code for the following instruction: sll$t2, $s0, 4 Registers have numbers: $t2 = 10, $s0 = 16 18

Exercise 4 Sol. sll$t2, $s0, 4 $t2 = 10, $s0 = 16 19

Exercise 5 Assemble the following MIPS instruction into real MIPS machine code: lw$t0, 32 ($s3) Registers have numbers: $t0 = 8, $s3 = 19 20

Exercise 5 Sol. lw$t0, 32 ($s3) $t0 = 8, $s3 = 19 21

Exercise 6 Show the real MIPS machine language version for the instruction addi$s1, $s2, 4 Registers have numbers: $s1 = 17, $s2 = 18 22

Exercise 6 Sol. addi$s1, $s2, 4 $s1 = 17, $s2 = 18 23

Exercise 7 Assuming that integer array A has its base in $t1 and that $s2 corresponds to integer variable h, show the real MIPS machine language code for A[300] = h + A[300]; Registers have numbers: $t0 = 8, $t1 = 9, $s2 = 18 MIPS: lw $t0,1200($s1) add $t0,$s2,$t0 sw$t0,1200($s1) 24

Exercise 7 Sol. 25