CSE 378 Midterm 2/12/10 Sample Solution

Similar documents
CSE 378 Midterm Sample Solution 2/11/11

Processor (I) - datapath & control. Hwansoo Han

CS3350B Computer Architecture Quiz 3 March 15, 2018

Machine Organization & Assembly Language

COMPUTER ORGANIZATION AND DESIGN. The Hardware/Software Interface. Chapter 4. The Processor: A Based on P&H

The Processor. Z. Jerry Shi Department of Computer Science and Engineering University of Connecticut. CSE3666: Introduction to Computer Architecture

Computer Organization and Structure

Chapter 4. The Processor. Computer Architecture and IC Design Lab

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Chapter 4. The Processor

CS 351 Exam 2 Mon. 11/2/2015

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

EECS150 - Digital Design Lecture 10- CPU Microarchitecture. Processor Microarchitecture Introduction

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

ECE232: Hardware Organization and Design

Chapter 4. The Processor

Lecture 4: Review of MIPS. Instruction formats, impl. of control and datapath, pipelined impl.

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

LECTURE 5. Single-Cycle Datapath and Control

EECS150 - Digital Design Lecture 9- CPU Microarchitecture. Watson: Jeopardy-playing Computer

The MIPS Processor Datapath

Pipeline design. Mehran Rezaei

Laboratory 5 Processor Datapath

Chapter 4 The Processor 1. Chapter 4A. The Processor

CSEN 601: Computer System Architecture Summer 2014

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Full Datapath. CSCI 402: Computer Architectures. The Processor (2) 3/21/19. Fengguang Song Department of Computer & Information Science IUPUI

Inf2C - Computer Systems Lecture Processor Design Single Cycle

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Chapter 4. The Processor

Codeword[1] Codeword[0]

Chapter 4. The Processor

CSE Quiz 3 - Fall 2009

Systems Architecture

EE557--FALL 1999 MAKE-UP MIDTERM 1. Closed books, closed notes

CSCI 402: Computer Architectures. Fengguang Song Department of Computer & Information Science IUPUI. Today s Content

Single Cycle CPU Design. Mehran Rezaei

Mark Redekopp and Gandhi Puvvada, All rights reserved. EE 357 Unit 15. Single-Cycle CPU Datapath and Control

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CENG 3420 Lecture 06: Datapath

NATIONAL UNIVERSITY OF SINGAPORE

The Processor: Datapath & Control

Improving Performance: Pipelining

COMP303 - Computer Architecture Lecture 8. Designing a Single Cycle Datapath

Review: Abstract Implementation View

EECS 151/251A Fall 2017 Digital Design and Integrated Circuits. Instructor: John Wawrzynek and Nicholas Weaver. Lecture 13 EE141

Lecture 4: MIPS Instruction Set

University of California College of Engineering Computer Science Division -EECS. CS 152 Midterm I

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY Computer Organization (COMP 2611) Spring Semester, 2014 Final Examination

Levels of Programming. Registers

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

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

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

Lecture 3: The Processor (Chapter 4 of textbook) Chapter 4.1

Introduction. Datapath Basics

Midterm. Sticker winners: if you got >= 50 / 67

The Evolution of Microprocessors. Per Stenström

Lecture Topics. Announcements. Today: Single-Cycle Processors (P&H ) Next: continued. Milestone #3 (due 2/9) Milestone #4 (due 2/23)

EC 413 Computer Organization - Fall 2017 Problem Set 3 Problem Set 3 Solution

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Processor Design Pipelined Processor (II) Hung-Wei Tseng

CS 61C Summer 2016 Guerrilla Section 4: MIPS CPU (Datapath & Control)

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

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

Adding Support for jal to Single Cycle Datapath (For More Practice Exercise 5.20)

Outline. A pipelined datapath Pipelined control Data hazards and forwarding Data hazards and stalls Branch (control) hazards Exception

CS 251, Winter 2019, Assignment % of course mark

CS2100 COMPUTER ORGANISATION

Department of Electrical Engineering and Computer Sciences Fall 2003 Instructor: Dave Patterson CS 152 Exam #1. Personal Information

ECS 154B Computer Architecture II Spring 2009

Chapter 4. The Processor Designing the datapath

COMPUTER ORGANIZATION AND DESIGN

Design of Digital Circuits 2017 Srdjan Capkun Onur Mutlu (Guest starring: Frank K. Gürkaynak and Aanjhan Ranganathan)

COMPUTER ORGANIZATION AND DESIGN

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

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

Machine Organization & Assembly Language

CC 311- Computer Architecture. The Processor - Control

Lecture 5: Procedure Calls

4. What is the average CPI of a 1.4 GHz machine that executes 12.5 million instructions in 12 seconds?

CS/COE1541: Introduction to Computer Architecture

MIPS%Assembly% E155%

CENG3420 Lecture 03 Review

CS 61C Fall 2016 Guerrilla Section 4: MIPS CPU (Datapath & Control)

CS 61C: Great Ideas in Computer Architecture. MIPS CPU Datapath, Control Introduction

ECE 15B Computer Organization Spring 2011

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

CPE 335 Computer Organization. Basic MIPS Architecture Part I

Chapter 5: The Processor: Datapath and Control

ECE 313 Computer Organization EXAM 2 November 11, 2000

Lecture 10: Simple Data Path

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

CS222: MIPS Instruction Set

Topic Notes: MIPS Instruction Set Architecture


Final Exam Spring 2017

Pipelined datapath Staging data. CS2504, Spring'2007 Dimitris Nikolopoulos

Transcription:

Question 1. (6 points) (a) Rewrite the instruction sub $v0,$t8,$a2 using absolute register numbers instead of symbolic names (i.e., if the instruction contained $at, you would rewrite that as $1.) sub $2, $24, $6 (b) Rewrite the instruction from part (a) in binary. Use vertical lines to show which fields of the instruction are which, and write the field names (op, rd, etc.) underneath the bits that make up that field. 000000 11000 00110 00010 00000 100010 op rs rt rd shamt funct Question 2. (6 points) What is the value of the decimal number -129 if it is converted to a 32-bit, 2 s-complement binary integer? your answer in hexadecimal. (Suggestion: It might be useful to show your intermediate steps so if there s a mistake it ll be easier to figure out what happened.) 0xffffff7f Page 1 of 8

Question 3. (6 points) Suppose we have the following 32-bit word labeled n located at address 0x1000001c in an assembly language program. [0x1000001c] n:.word 42 MIPS assembly language allows us to write lw $t0,n to load this word into register $t0. Although lw is a real machine instruction and not a pseudo-instruction, this line of assembly language code cannot be translated into a single machine instruction because the address 0x1000001c does not fit into the 16-bit offset field in a single lw instruction. Give a sequence of two actual machine instructions that perform the desired lw $t0,n operation and that could be used in a program without interfering with surrounding instructions. your answer using symbolic assembly language notation, not binary. lui lw $t0, 0x1000 $t0, 0x1c($t0) It would also be ok to use $at for the address register. Page 2 of 8

Question 4. (22 points) MIPS Hacking. A fast way to search an unordered list is a sentinel search, where we place the item we are looking for at the end of the list after all the data currently in it, then search until we find it and report whether it was found at the sentinel location or earlier. For this problem, write a MIPS assembly language version of the following C sentinel search function. /* Search for x in A[0..n-1]. Return 1 if found, else 0. */ /* Precondition: A has capacity for n+1 or more int values */ int find(int x, int A[], int n) { A[n] = x; k = 0; while (A[k]!= x) { k++ } if (k < n) return 1; else return 0; } You should use the standard MIPS calling and register conventions (initially, $a0 = value of x, $a1 = address of array A, $a2 = value of n). You do not need to allocate a stack frame if you do not need one. You may use either explicit subscripting operations or pointers or both to reference array elements, whichever is more convenient. Include brief comments to make it easier to follow your code. your answer on the next page. (You can tear this page out for reference while you work, if that is helpful.) Page 3 of 8

Question 4. (cont.) your answer here. C code repeated for reference (reformatted to save space). /* Search for x in A[0..n-1]. Return 1 if found, else 0. */ /* Precondition: A has capacity for n+1 or more int values */ int find(int x, int A[], int n) { A[n] = x; k = 0; while (A[k]!= x) { k++ } if (k < n) return 1; else return 0; } find: sll $t1, $a2, 2 # $t1 = &A[n] add $t1, $t1, $a1 sw $a0, 0($t1) # A[n] = x loop: lw $t0, 0($a1) # $t0 = A[k] (k=0 initially) beq $a0, $t0, found # branch if A[k] is x addi $a1, 4 # k++ j loop # repeat found: slt $v0, $a1, $t1 # result = &A[k] < &A[n] jr $ra # return There are, of course, many other ways to solve the problem. Page 4 of 8

The following question concerns the single-cycle MIPS datapath shown below. 0 PC 4 Add Reg Shift left 2 Add M u x 1 PCSrc address Instruction memory Instruction [31-0] I [25-21] I [20-16] I [15-11] 0 M u x 1 register 1 register 2 register data Registers data 1 data 2 0 M u x 1 ALU ALUOp Zero Result address address data Mem data Data memory MemToReg 1 M u x 0 RegDst ALUSrc Mem I [15-0] Sign extend Question 5. (20 points) For each of the following instructions, fill in the blanks in the table below to indicate the settings of the control signals to execute that instruction. Each control signal must be specified as 0, 1, or X (don t care). Writing a 1 or a 0 when an X is more accurate is not correct. If a control signal is a logical function of one or more other signals, write that function. For ALUOp, you can write things like add or xor, since we don t expect you to have memorized the binary ALUOp signals. Opcode RegDst Reg ALUSrc ALUOp Mem Mem MemToReg PCSrc sub 1 1 0 sub 0 0 0 0 lw 0 1 1 add 0 1 1 0 bne X 0 0 sub 0 0 X!Zero Page 5 of 8

Question 6. (20 points) Suppose we want to add a new R-format instruction to the MIPS ISA to compute the absolute value of a 32-bit integer. The new instruction is abs rd,rs, and it stores the absolute value of rs in rd. A diagram of the simple 5-stage MIPS pipelined CPU we will modify is on the next page. (a) To implement this instruction, we decide to add a new module to the datapath. Complete the following Verilog module abscomp so that it generates the absolute value of inval on the output absval. (Don t be alarmed if the solution is quite short.) module abscomp(inval, absval); input wire [31:0] inval; output wire [31:0] absval; assign absval = inval[31]? inval : inval; endmodule (continued on next page) Page 6 of 8

Question 6. (cont.) (b) The following diagram is a simple version of the 5-stage MIPS pipelined CPU from class. The controller has a new output wire named ABS, which is high when the controller decodes an abs instruction and low otherwise. Add in and properly wire up the abscomp module from part (a) into this datapath Note: This is only one of many possible solutions. All correct solutions involve adding the module, adding a multiplexer to choose between the module s output and the value of R[rs], and using a properly-forwarded ABS control line from the ID stage as the select for the added mux. It would also be ok to place the module between the ALU and the EX/MEM latch. In a real circuit, the best placement would need to take into account timing and delay issues, among other things. Page 7 of 8

Question 7. (20 points) Pipeline hazards. Consider this sequence of MIPS instructions addi $t1, $zero, 17 lw $t2, 0($a0) add $v0, $t1, $t2 lw $t3, 4($a0) add $v0, $v0, $t3 (a) Describe all of the data dependencies in the above instructions. You can draw arrows on the instructions above to show your answer or you can write an explanation below. (b) Assuming that we execute these instructions as written on a processor with a 5-stage pipeline with forwarding, fill in the diagram below to show how this sequence of instructions executes. Show stalls in the schedule, if any, by writing stall in that square. The first row for the addi instruction and the first two cycles of the next two instructions are written for you. cycle 1 2 3 4 5 6 7 8 9 10 11 12 addi IF ID EX MEM WB lw IF ID EX MEM WB add IF ID stall EX MEM WB lw IF ID stall EX MEM WB add IF ID stall stall EX MEM WB (c) Reorder the instructions into a new schedule (sequence) so they will execute without any stalls on a 5-stage pipeline with forwarding, if that is possible, or as few stalls as possible. the reordered instructions below. Any schedule that does not use the result of either load as an operand in the immediately following instruction will work. Here s one. lw $t2, 0($a0) lw $t3, 4($a0) addi $t1, $zero, 17 add $v0, $t1, $t2 add $v0, $v0, $t3 How many stall cycles are there in your new schedule above, if any? 0 Page 8 of 8