Computer Architecture I Midterm I

Similar documents
University of California, Berkeley College of Engineering

Computer Architecture I Mid-Term I

University of California, Berkeley College of Engineering

Midterm. CS64 Spring Midterm Exam

Computer Architecture I Midterm I (solutions)

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

CS 61c: Great Ideas in Computer Architecture

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

University of California, Berkeley College of Engineering

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm

University of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)

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

CS61c MIDTERM EXAM: 3/17/99

UCB CS61C : Machine Structures

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

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

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

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

MIPS Functions and Instruction Formats

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

CS61C : Machine Structures

CS 351 Exam 2 Mon. 11/2/2015

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

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

Lecture 5: Procedure Calls

Levels of Programming. Registers

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

We will study the MIPS assembly language as an exemplar of the concept.

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 5 2/22/2018

University of California, Berkeley College of Engineering

Fall 2010 CS61C Midterm 1 Solutions

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

ECE 30 Introduction to Computer Engineering

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

CSE 378 Final Exam 3/14/11 Sample Solution

CS 110 Computer Architecture MIPS Instruction Formats

Lecture 4: MIPS Instruction Set

Assembly Programming

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Chapter 2A Instructions: Language of the Computer

CDA3100 Midterm Exam, Summer 2013

COMPUTER ORGANIZATION AND DESIGN

Unsigned Binary Integers

Unsigned Binary Integers

Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures

University of California, Berkeley College of Engineering

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

Run time environment of a MIPS program

Q1: /30 Q2: /25 Q3: /45. Total: /100

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

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

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

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

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

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

University of California, Berkeley College of Engineering

Winter 2002 FINAL EXAMINATION

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

ECE331: Hardware Organization and Design

Winter 2012 MID-SESSION TEST Tuesday, March 6 6:30pm to 8:15pm. Please do not write your U of C ID number on this cover page.

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

University of California, Berkeley College of Engineering

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Programming the processor

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

CS64 Week 5 Lecture 1. Kyle Dewey

Name: University of Michigan uniqname: (NOT your student ID number!)

CENG3420 Lecture 03 Review

MIPS Instruction Set

MIPS Assembly Programming

CS 110 Computer Architecture MIPS Instruction Formats

Instructions: Language of the Computer

Thomas Polzer Institut für Technische Informatik

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

CSE Lecture In Class Example Handout

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

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

CS 110 Computer Architecture Review for Midterm I

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

ECE331: Hardware Organization and Design

Transcription:

Computer Architecture I Midterm I April 11 2017 Computer Architecture I Midterm I Chinese Name: Pinyin Name: E-Mail... @shanghaitech.edu.cn: Question Points Score 1 1 2 12 3 16 4 14 5 18 6 17 7 22 Total: 100 This test contains 10 numbered pages, including the cover page, printed on both sides of the sheet!. We will use gradescope for grading, so only answers filled in at the obvious places will be used. Use the provided blank paper for calculations and then copy your answer here. Please turn off all cell phones, smartwatches, and other mobile devices. Remove all hats and headphones. Put everything in your backpack. Place your backpacks, laptops and jackets under your seat. You have 85 minutes to complete this exam. The exam is closed book; no computers, phones, or calculators are allowed. You may use one A4 page (front and back) of notes in addition to the provided green sheet. The estimated time needed for each of the 6 topics is given in parenthesis. The total estimated time is 80 minutes. 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. Do NOT start reading the questions/ open the exam until we tell you so! Unless otherwise stated, always assume a 32 bit machine for this midterm. 1. 1 First Task (worth one point): Fill in you name Fill in your name and email on the front page and your ShanghaiTech email on top of every page (without @shanghaitech.edu.cn) (so write your email in total 8 times).

Email: Midterm I, Page 2 of 10 Computer Architecture I 2017 2. Various Questions (12 pts; 10 min) 3 (a) Name 6 Great Ideas in Computer Architecture. Solution: 1. Abstraction (Layers of Representation/Interpretation) 2. Moores Law (Designing through trends) 3. Principle of Locality (Memory Hierarchy) 4. Parallelism 5. Performance Measurement and Improvement 6. Dependability via Redundancy 2 (b) 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? Solution: They CAN be different because the address of foo (which will be a part of the recursive jal call) depends on where the code is placed. 2 (c) What is the difference between the add and addu MIPS instructions? (c) add may cause an overflow exception, while addu will not. 2 (d) Which MIPS registers are preserved over a function call (write all register names - e.g. $m2-$m6)? (d) 1 (e) How many things can you represent with N bits? $s0-$s7, $gp, $sp, $fp (e) 2 (f) In the lecture you learned about CALL (this is the CALL regarding executing a C program on a computer). Name (each a single word) the important steps of this procedure in the right order. Solution: Compiler Assembler Linker Loader 2 N

Email: Midterm I, Page 3 of 10 Computer Architecture I 2017 3. Number Representation (16 pts; 15 min) Please convert the following 8-bit Signed Integers into decimal form. Explicitly write + and -. For example, suppose that the binary representation is 01000001B and it is represented in Sign-Magnitude Representation, then the solution is +65D. 2 (a) If represented in Sign-Magnitude Representation Suppose the binary representation is 10000001B: Suppose the binary representation is 10000000B: Solution: -1D -0D 2 (b) If represented in 2 s Complement Representation Suppose the binary representation is 10000001B: Suppose the binary representation is 11111111B: Solution: -127D -1D 4 (c) Suppose a is an 8 bit signed integer represented as a hex = 0xCB, then its binary representation is a two =, its decimal representation is a ten =. Solution: Answer: 11001011, -53 4 (d) For an 10-bit value, two s complement integer, what are the largest AND smallest value you can represent in decimal? Solution: Answer: 511, -512 4 (e) Assume an 8-bit two s complement machine on which all operators are performed on 8- bit registers. Answer the results of the following operations in hexadecimal. Assume that subtraction is done with SUBU and addition is done with ADDU. a 8C (hex) B5 (hex) b 8A (hex)

Email: Midterm I, Page 4 of 10 Computer Architecture I 2017 + 3E (hex) Solution: Answer: D7, C8

Email: Midterm I, Page 5 of 10 Computer Architecture I 2017 4. C programming I (14 pts; 14 min) 4 (a) What is the value of s in the following code? If possible, also provide the actual number in decimal. unsigned int t[] = {0, 1, 2, 3, 4, 5; unsigned int s = sizeof(t); (I) The length of the t array. (II) The number of bytes in the t array. (III) The number of bytes in one unsigned int. (IV) The number of bytes in an unsigned int pointer. (V) Nothing: an error will be produced. (a) II; 24 5 (b) What does the following method do? char * func(char *f, char y){ char *h = f; for(h = f; *h!= y && *h){ h++; if(*h){ *h = 0; h++; return h; (I) It returns a pointer to the first location of y in f. (II) It splits f at the first occurrence of y and then returns a pointer for the remaining string. (III) It finds the last location of y in f, zeros put that location, and then returns a pointer to the next location. (IV) It zeros out f until it finds y. It then returns a pointer to the location of y in f. (V) Nothing; it cannot be complied. (b) IV or V (missing semicolon in the for loop) 5 (c) The %s format specifier takes in a char* and prints until it finds a null character. What do the following two lines of code print? char *s = "uncharacteristic"; printf("%s", s+s[7]-s[6]); (c) characteristic

Email: Midterm I, Page 6 of 10 Computer Architecture I 2017 5. C programming II (18 pts; 10 min) 9 (a) Given the code below: int a; const char * b; int foo(short c){ char d; static int * e = malloc(sizeof(int)); int main(){ int f; foo(3); Name all areas of memory that are used by the program: (a) Static data; stack; heap At which area of the memory are the following variables stored: a: b: c: d: e: f: Solution: a: static data b: static data c: stack (or register) d: stack e: static data f: stack 9 (b) 1. When passing parameters to functions, what is the difference between call by value and call by reference? 2. What is the default function call method in (I) MIPS and (II) C?

Email: Midterm I, Page 7 of 10 Computer Architecture I 2017 3. How can we achieve the other call method? Solution: 1. call by value Use the value of parameter, but not modify it. call by reference Send address of the actual parameters instead of values. Want the parameters be modified. 2. By default the functions are called by value in both MIPS and C. 3. Passing a pointer to the value

Email: Midterm I, Page 8 of 10 Computer Architecture I 2017 6. Bits and Pieces (17 pts; 15min) Read the following MIPS assembly code and answer the following questions. Your answers should be as concise as possible. halo: #BEGIN addiu $v0, $0, 0 addiu $s0, $0, 0 addiu $s1, $0, 0 beq $a0, $0, finish_the_fight addiu $s0, $a0, 0 addiu $s1, $0, 1 andi $t0, $s0, 1 new_mombasa: bne $t0, $0, finish_the_fight srl $s0, $s0, 1 sll $s1, $s1, 1 andi $t0, $s0, 1 j new_mombasa finish_the_fight: addiu $v0, $s1, 0 #END jr $ra 4 (a) Briefly explain what halo returns with respect to the input. Solution: Get the lowest positive bit from the input number. 7 (b) Try to implement the function in C as efficient and concise as possible. (The space given below is more than enough.) Solution: int masterchief(int cortana){ return cortana & (ˆcortana + 1);

Email: Midterm I, Page 9 of 10 Computer Architecture I 2017 6 (c) We ve broken some assembly language calling conventions with the code above. Write the code that should be inserted at the positions of #BEGIN and #END to correct it. At #BEGIN: Solution: addiu $sp $sp -8 sw $s0, 0($sp) sw $s1, 4($sp) At #END: Solution: lw $s0, 0($sp) lw $s1, 4($sp) addiu $sp $sp 8 7. MIPS & Branch-if-equal instruction (22pts; 16 min) 10 (a) True/False: circle the correct answer (2 pts each) T F 1. Branch instructions in MIPS can only jump forward 32768 and backward 32767 instructions. T F 2. A carry-out at the most significant bit after an addition of two signed numbers always indicates overflow. T F 3. I-type instructions always cause pipeline bubbles. T F 4. If we only have three parameters to send to a non-recursive function, then we can use registers and don t need to use the stack. T F 5. Every location in the text segment is accessible from a single branch statement. Solution: 1. T (a branch with an immediate of 0 jumps forward 1 instruction) 2. F (operations with a negative result will always have carry-out.) 3. F 4. T 5. F

Email: Midterm I, Page 10 of 10 Computer Architecture I 2017 6 (b) Consider a hypothetical branch-if-equal instruction that is 32 bits long: - 6 bits are used to encode the opcode - 6 bits are used to encode one register number - 6 bits are used to encode another register number - 14 bits are used to encode an offset that will be added to the program counter (PC) if the branch ends up being taken, and a new instruction address is required. (The number is not in 2 s complement form, and all 14 bits can encode a constant.) Thus, the instruction syntax might be: BEQ R12, R11, X - If R12==R11, the PC will be set to PC+X instead of PC+4. Given this instruction, is the code shown in the table below valid? Why or why not? Explain in detail. Address Instruction 5000... 5004 BEQ R12, R11, X 5008 Add R1, R2, R3...... X: 21256 Sub R1, R2, R3 Solution: Yes, this code is valid. The 14 bit offset allows you to encode a number that is as large as 16383. Thus, even if the PC has not yet been incremented, you can reach address 21384 (5004 + 16383), which is beyond address 21256. Since it was not super clear we also allow: No, the code is not valid. The 14 bit offset allows you to encode a sign-magnitude number as large as 8191, we can reach maximum 13196, which cannot reach 21256. 6 (c) Instruction Format: Translate the assembly into machine code and vice versa (use named registers - not register numbers). Instruction lb $t3, 7($s5) sll $s1, $s2, 8 Code (hex) 0x82ab0007 0x00128a00