Department of Electrical Engineering and Computer Sciences Spring 2013 Instructor: Dr. Dan Garcia CS61C Midterm

Similar documents
Department of Electrical Engineering and Computer Sciences Spring 2007 Instructor: Dr. Dan Garcia

University of California, Berkeley College of Engineering

Department of Electrical Engineering and Computer Sciences Spring 2010 Instructor: Dr. Dan Garcia CS61C Midterm

CS61C Midterm After the exam, indicate on the line above where you fall in the emotion spectrum between sad & smiley...

Department of Electrical Engineering and Computer Science Spring 2004 Instructor: Dan Garcia CS61C Midterm

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

CS61C Midterm After the exam, indicate on the line above where you fall in the emotion spectrum between sad & smiley...

Computer Architecture I Midterm I

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

3) Cache, money. Dollar bills, y all. (24 min, 15 pts)

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

Question 6: Cache in While You Can (17 points, 26 Minutes)

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

Midterm. CS64 Spring Midterm Exam

University of California, Berkeley College of Engineering

University of California, Berkeley College of Engineering

CS61c Summer 2014 Midterm Exam

UC Berkeley CS61C Fall 2018 Midterm

University of California, Berkeley College of Engineering

Name: Login: cs61c- Decimal Ternary 5 12 three three

CS61C Final After the exam, indicate on the line above where you fall in the emotion spectrum between sad & smiley...

University of California, Berkeley College of Engineering

Computer Architecture I Mid-Term I

University of California, Berkeley College of Engineering

CS61c Summer 2014 Midterm Exam

Department of Electrical Engineering and Computer Sciences Fall 2017 Instructors: Randy Katz, Krste Asanovic CS61C MIDTERM 2

Department of Electrical Engineering and Computer Sciences Fall 2016 Instructors: Randy Katz, Bernhard Boser

CS 61C, Fall, 2005, Midterm 1, Garcia Question 1: For those about to test, we salute you (11 pts, 20 min.)

Department of Electrical Engineering and Computer Sciences Fall 2016 Instructors: Randy Katz, Bernhard Boser

University of California, Berkeley College of Engineering

CSE351 Spring 2018, Final Exam June 6, 2018

Fall 2010 CS61C Midterm 1 Solutions

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

Do not turn the page until 12:30.

CS61C Summer 2013 Final Exam

ECE264 Fall 2013 Exam 3, November 20, 2013

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

CS61C : Machine Structures

Computer Architecture I Midterm I (solutions)

CS61C Final Exam After the exam, indicate on the line above where you fall in the emotion spectrum between sad & smiley...

F2) Don t let me fault (22 pts, 30 min)

Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

Nick Weaver Sp 2019 Great Ideas in Computer Architecture MT 1. Print your name:,

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

CS61C Summer 2013 Midterm

CS Operating system

M3) Got some numbers, down by the C (10 pts, 20 mins)

CS61c MIDTERM EXAM: 3/17/99

Question Points Score Total: 100

UCB CS61C : Machine Structures

The University of Michigan - Department of EECS EECS 370 Introduction to Computer Architecture Midterm Exam 1 February 17, 2011

Assembler. #13 Running a Program II

CS61C : Machine Structures

University of California, Berkeley College of Engineering

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

CPSC 213, Summer 2017, Term 2 Midterm Exam Solution Date: July 27, 2017; Instructor: Anthony Estey

8*4 + 4 = 36 each int is 4 bytes

CS16 Midterm Exam 1 E01, 10S, Phill Conrad, UC Santa Barbara Wednesday, 04/21/2010, 1pm-1:50pm

Winter 2006 FINAL EXAMINATION Auxiliary Gymnasium Tuesday, April 18 7:00pm to 10:00pm

Virtual Memory Overview

CS61C : Machine Structures

Computer Systems Programming. Practice Midterm. Name:

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

CS61C : Machine Structures

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

MIPS Functions and Instruction Formats

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

CS , Fall 2001 Exam 2

Signature: 1. (10 points) Basic Microcontroller Concepts

CS61C : Machine Structures

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

ECE 30 Introduction to Computer Engineering

ECE264 Spring 2013 Final Exam, April 30, 2013

Section I B COMPUTER SCIENCE SOLUTION

CS 61c: Great Ideas in Computer Architecture

Question F5: Caching [10 pts]

CENG3420 Lecture 03 Review

Do not turn the page until 12:30.

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

Introduction to Computer Systems. Exam 2. April 11, Notes and calculators are permitted, but not computers.

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

CS61C Summer 2013 Final Review Session

CS61C : Machine Structures

CS , Fall 1998 Final Exam

CS 61B: Midterm Exam I

CPSC 213, Summer 2017, Term 2 Midterm Exam Date: July 27, 2017; Instructor: Anthony Estey

Transcription:

University of California, Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences Spring 2013 Instructor: Dr. Dan Garcia 2013-03-04 CS61C Midterm After the exam, indicate on the line above where you fall in the emotion spectrum between sad & smiley... Last Name First Name Student ID Number Login Login First Letter (please circle) Login Second Letter (please circle) cs61c- a b c d e f g h i j k l m a b c d e f g h i j k l m n o p q r s t u v w x y z The name of your LAB TA (please circle) Justin Alan Paul Sagar Sung-Roa Zachary Name of the person to your Left Name of the person to your Right All the work is my own. I had no prior knowledge of the exam contents nor will I share the contents with others in CS61C who have not taken it yet. (please sign) Instructions (Read Me!) Don t Panic! This booklet contains 6 numbered pages including the cover page. Put all answers on these pages; don t hand in any stray pieces of paper. Please turn off all pagers, cell phones & beepers. Remove all hats & headphones. Place your backpacks, laptops and jackets at the front. Sit in every other seat. Nothing may be placed in the no fly zone spare seat/desk between students. You have 120 minutes to complete this exam. The exam is open book, no computers, PDAs, calculators. There may be partial credit for incomplete answers; write as much of the solution as you can. We will deduct points if your solution is far more complicated than necessary. When we provide a blank, please fit your answer within the space provided. You have 2 hours...relax. Question 1 2 3 4 Total Minutes 48 24 24 24 120 Points 30 15 15 15 75 Score

1) What is that funky smell? Oh, it s just Potpourri (48 min, 30 pts) Suppose for questions (a)-(d) that we were to modify the MIPS ISA so that it exposed 64 registers instead of 32, and adjusted the field widths of our R, I and J instruction formats to be able to address all the registers, but did not change the size of the opcode or shamt fields. Registers and instructions will remain 4 bytes wide. a) At most how many instructions can a single beq instruction now reach? b) How many more addresses can now be reached from a jal instruction? c) How many different R-type instructions can we now have? d) If it costs 256 cents per bit of register memory (yikes!), how much would these 64 registers cost, in cents? Answer using IEC notation (e.g,. 4 mebicents). Questions (e)-(g) concern the IEEE floating point standard. e) What float is encoded by the following bits: 0xc14c0000? (show all work here) f) What is the smallest positive normalized number? Number: encoded as 0x (show all work here) g) Write the MAL MIPS function IsNotInfinity to return non-0 if the input is NOT ±, 0 if it is ±. IsNotInfinity: $a0 $a0 1 ### make and + look the same jr $ra 2/6

Login: cs61c- 1) What is that funky smell? Oh, it s just Potpourri (continued) h) Complete the below C code so that it obeys its comments. This should work on 1986 hardware, where ints were only 2 bytes wide, as well on our current 32-bit MIPS machines. #define INT_BITS ; // # bits in an int // Rotates (the numeral that p points to) to the left by 0<=n<INT_BITS. // rotate means the leftmost bits fall off the left, appear on the right void drotl(unsigned int *p, unsigned int n) { ; i) You define a short recursive MIPS procedure foo that is statically linked by two executables. Can the binary for the procedure foo be different in the two executables? Why, or why not? j) We want to represent 10-digit phone numbers using bits. Assume that any combination of 10 digits is legal. One scheme is to represent each digit with a certain number of bits, then repeat it 10 times. What is the minimum number of bits required to represent a phone number using this scheme? k) Using any scheme, what is the fewest number of bits required to address all phone numbers? l) Consider the C code here, and assume the malloc call succeeds. Rank the following values from 1 to 5, with 1 being the least, right before bar returns. Use the memory layout from class; Treat all addresses as unsigned #s. foo &foo FIVE &FIVE &x #include <stdlib.h> int FIVE = 5; int bar(int x) { return x * x; int main(int argc, char *argv[]) { int *foo = malloc(sizeof(int)); if (foo) free(foo); bar(10); // snapshot just before it returns return 0; 3/6

2) free at last, thank gosh we are free at last (24 min, 15 pts) We wish to free a linked list of strings (example below) whose nodes are made up of this struct. Complete the code below; we have started you off with some filled in. You may use fewer lines, but do not add any. FreeLL: beq,, NULL_CASE jal FreeLL lw $a0 0($sp) jal free // Assume compiler packs tightly struct node { char *string; struct node *next; ; void FreeLL(struct node *ptr) { if (ptr == NULL) return; else { FreeLL(ptr->next); free(ptr->string) free(ptr); NULL_CASE: jr $ra head I love CS61C midterms! 4/6

Login: cs61c- 3) Cache, money. Dollar bills, y all. (24 min, 15 pts) Suppose we have a standard 32-bit byte-addressed MIPS machine, a single direct-mapped 32KiB cache, a write-through policy, and a 16B block size. a) Give the T:I:O breakup. b) How many bits are there per row on the cache? Use the C code below and the description of the cache above to answer the questions that follow it. Suppose that the only memory accesses are accesses and stores to arrays and that all memory accesses in the code are valid. Assume A starts on a block boundary (byte 0 of A in byte 0 of block). #define NUM_INTS 32 #define OFFSET 8192 // 8192 = 2^13 int rand(int x, int y); // returns a random integer in the range [x, y) int main(){ int A[NUM_INTS + OFFSET]; // Assume A starts on a block boundary // START LOOP 1 for ( int count = 0 ; count < NUM_INTS ; count += 1 ) { // count by 1s A[count] = count; // ACCESS #1 A[count + OFFSET] = count+count; // ACCESS #2 // END LOOP 1 // START LOOP 2 for ( int count = 0 ; count < NUM_INTS ; count += 4 ) { // count by 4s now for ( int r = 0 ; r < 4 ; r++ ) { // but do it 4 times printf( %d, A[rand(count, count+4)]); // END LOOP 2 c) Hit rate for Loop 1? What types of misses are there? d) Hit rate for Loop 2? What types of misses are there? Questions (e), (f), and (g) below are three independent variations on the original code & settings. e) If the cache were 2-way set associative, what would be the hit rate for Loop 2? (assume the standard LRU replacement policy) f) If instead we removed the line labeled ACCESS #2, what would be the hit rate for Loop 2? g) Instead, what s the smallest we could shrink OFFSET to maximize our Loop 2 hit rate? (assume we still need to maintain the same functionality) 5/6

4) You thought YOUR numbers were big? Try these! (24 min, 15 pts) We d like to represent infinitely long positive integers. We decide to use an array of DIGITs, where a DIGIT is an unsigned 8-bit quantity specified by uint8_t. We d also like to know where the number ends, so we ll declare 0xF to be the terminator (like 0x0 is for strings). Let s see how we d store 57 : Byte 2 1 0 Bit 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 Hex 0 F 0 5 0 7 a) Fill in adddigit to make it work properly. The idea is that we ll build this small black box that can add one DIGIT as shown below, then to add the whole thing we ll virtually hook many of these together. This block simulates what we do when we are adding, say, the tens column on the right: da is 2, db is 7, carryin from the ones column is 1, carryout for the hundreds column gets 1 and the return value is 0. 1 1 1 2 8 + 7 7 0 5 typedef uint8_t DIGIT; DIGIT adddigit(digit da, DIGIT db, DIGIT carryin, DIGIT *carryout) { uint8_t tempsum = return carryout b) Now, let s use adddigit to write the full adder! Unfortunately, there are bugs; indicate your changes to fix the code in the table below. We use two helpers, sizeofdigit(), which would return 2 for the 57 example above, and safedigit() which takes an array A, index and length returning A[index] if we re still in array bounds (index < length), and 0 otherwise. A, B are never NULL. 01 DIGIT *add-digits(digit *A, DIGIT *B) { 02 unsigned int lena = sizeofdigit(a); 03 unsigned int lenb = sizeofdigit(b); 04 05 DIGIT sum[max(lena,lenb)]; /* make space for the answer */ 06 DIGIT carryin = 0, carryout; 07 int i; 08 for(i=0 ; i < max(lena,lenb) ; i++) { 09 sum[i] = adddigit(safedigit(a,i,lena), safedigit(b,i,lenb), carryin, carryout); 10 carryin = carryout; 11 12 13 sum[i] = 0xF; /* terminator */ 14 return sum; 15 Line Indicate the fix here and what it is (insertion, deletion, change). All lines not nec needed. da db adddigit carryin 6/6