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

Similar documents
ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam Solutions 9 December 2015

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

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

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

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

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

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

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 18 November 2015

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

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

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 19 November 2014

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

Week 10: Assembly Programming

Assembly Programming

Reduced Instruction Set Computer (RISC)

MIPS Instruction Reference

ECE 2035 Programming Hw/Sw Systems Spring problems, 8 pages Final Exam Solutions 1 May 2013

F. Appendix 6 MIPS Instruction Reference

ECE 2035 Programming HW/SW Systems Fall problems, 4 pages Exam Three 14 November Your Name (please PRINT clearly) Signed.

MIPS Reference Guide

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

Reduced Instruction Set Computer (RISC)

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Computer Architecture. The Language of the Machine

ECE 15B Computer Organization Spring 2010

ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam Solutions 14 December 2016

Computer Architecture. MIPS Instruction Set Architecture

ECE 2035 Programming HW/SW Systems Spring problems, 5 pages Exam Three 8 April Your Name (please print clearly)

MIPS Instruction Set

TSK3000A - Generic Instructions

ECE Exam I February 19 th, :00 pm 4:25pm

CS 61c: Great Ideas in Computer Architecture

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

The MIPS Instruction Set Architecture

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

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

SPIM Instruction Set

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

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

Programming the processor

MIPS Instruction Format

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

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

Q1: /14 Q2: /12 Q3: /8 Q4: /8. Total: /42

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

MIPS Assembly Language. Today s Lecture

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Arithmetic for Computers

Lec 10: Assembler. Announcements

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

MIPS%Assembly% E155%

CPS311 - COMPUTER ORGANIZATION. A bit of history

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

CSc 256 Final Fall 2016

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

CSc 256 Midterm 2 Fall 2011

CSc 256 Midterm (green) Fall 2018

Mips Code Examples Peter Rounce

CSc 256 Midterm 2 Spring 2012

M2 Instruction Set Architecture

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

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

CMPE324 Computer Architecture Lecture 2

Computer Architecture Experiment

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

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

Examples of branch instructions

Chapter 2A Instructions: Language of the Computer

MIPS Assembly Language

Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

Flow of Control -- Conditional branch instructions

MACHINE LANGUAGE. To work with the machine, we need a translator.

Exam in Computer Engineering

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

Concocting an Instruction Set

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

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

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

Review: MIPS Organization

Review of instruction set architectures

CSc 256 Final Spring 2011

INSTRUCTION SET COMPARISONS

Lecture 7: Procedures

Transcription:

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate the pages of the exam. For maximum credit, show your work. Good Luck! Your Name (please pr) This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give nor receive unauthorized assistance on this exam and to abide by all provisions of the Honor Code. Signed 1 2 3 4 5 6 total 20 30 25 20 30 40 165 1

Problem 1 (20 pos) Optimization Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version (in C) to the right. Assume square, f, and g are pure functions that each return an eger with no side effects to other data structures. square ( n) { return (n*n); f ( m) { g ( c, d) { mycode( a, b) { x = 100; y = 1, z=64; do { if (z) y += x*square(z); else y += g(z+a*x, y+a*x); prf("x:%d, y:%d\n",x,y); x--; while(x>f(y*1024) + g(a, b)); return g(y, x); Briefly describe which standard compiler optimizations you applied and how they improve storage and/or execution efficiency in this code example (be specific; e.g., replaces 2 MIPS operations with 1 operation on every loop iteration ). 1. 2. 3. 4. 5. 2

Problem 2 (2 parts, 30 pos) Suppose we have the following definition which is used to create singly linked lists. typedef struct Link { ID; Value; struct Link *Next; Link; Linked Lists Part A (6 pos) Complete the following subroutine which inserts a Link (poed to by the input parameter NewLink) o the list just after the Link poed to by the input parameter Before. You may assume that neither input parameter is NULL. Before s Next field may po to another Link or it may be NULL. NewLink s Next field is NULL. void SpliceIn(Link *NewLink, Link *Before){ ; /* part A*/ ; /* part A*/ Part B Complete the following recursive subroutine which takes a poer to the head of a linked list and returns a poer to a copy of the linked list. Follow the steps specified below. Link * CopyList(Link *Head) { if (Head == NULL) return ; /* part B.1 */ ; /* part B.2 */ ; /* part B.3 */ if ( ){ /* part B.4 */ prf( Error: Insufficient space. ); exit(1); return LinkCopy; Part B.1 (3 pos) Fill in what should be returned if the list is empty. ; /* part B.5 */ ; /* part B.5 */ ; /* part B.6 */ Part B.2 (3 pos) Add a local variable called LinkCopy that is a poer to a Link object. Part B.3 (5 pos) Allocate space for a Link structure using malloc and make LinkCopy po to the object allocated. Be sure to include appropriate type casting to avoid type errors. Part B.4 (3 pos) Fill in the test for whether malloc found enough space which controls the pr statement. Part B.5 (5 pos) Copy the values of Head s ID and Value fields to LinkCopy. Part B.6 (5 pos) Call CopyList recursively to copy the rest of the list and assign the result to LinkCopy s Next field. 3

Problem 3 (3 parts, 25 pos) Consider a hash table that is implemented using the following struct definitions. #define NUMBUCKETS 5 typedef struct Entry { Key; Value; struct Entry *Next; Entry; Associative Sets typedef struct { Entry HashTable; *Buckets[NUMBUCKETS]; Size; Part A (6 pos) What is the value of each of these (assume a 32 bit system): sizeof(entry) = sizeof(hashtable) = Part B (10 pos) Suppose the entries are maained in a sorted linked in each bucket in order from small to large keys. Complete the C function Find_Key that efficiently searches the hash table for an entry corresponding to a specified key (i.e., it should end the search as early as possible). It should return a poer to the matching Entry if Key is found or return NULL if Key is not found in the hash table. Entry *Find_Key(HashTable *HT, Key) { Entry *ThisEntry; Index; Hash( Key); /* function prototype for hash function */ Part C (9 pos) Suppose a hash table created using the structs above contains 155 entries total and the entries are evenly distributed across the 5 hash table buckets, each implemented as a sorted linked list of Entry structs. An application performs 500 lookups of various keys: 375 of the lookups find the key in the list and 125 lookups fail to find the key. The keys that are found are distributed throughout the list so that each position is equally likely to be where a key is found. What is the average number of key comparisons that would be needed for a lookup in this list implementation? (Show work. Note: you may not have to use all data provided.) Average number of comparisons: 4

Problem 4 (3 parts, 20 pos) Garbage Collection Below is a snapshot of heap storage. Values that are poers are denoted with a $. The heap poer is $6188. The heap has been allocated contiguously beginning at $6000, with no gaps between objects. addr value addr value addr value addr value addr value addr value 6000 8 6032 12 6064 20 6096 16 6128 12 6160 $6000 6004 33 6036 28 6068 4 6100 $6052 6132 $6172 6164 0 6008 0 6040 $6120 6072 $6132 6104 6010 6136 $6016 6168 16 6012 16 6044 80 6076 8 6108 5 6140 72 6172 $6052 6016 $6100 6048 16 6080 $6148 6112 148 6144 20 6176 0 6020 $6172 6052 0 6084 $6172 6116 8 6148 6046 6180 $6000 6024 25 6056 100 6088 4 6120 32 6152 $6080 6184 0 6028 30 6060 0 6092 $6080 6124 $6080 6156 26 6188 0 Part A (9 pos) Suppose the stack holds a local variable whose value is the memory address $6120 and register $3 holds memory address $6016. No other registers or static variables currently hold heap memory addresses. List the addresses of all objects in the heap that would be marked by a mark-and-sweep garbage collection algorithm. Addresses of Marked Objects: Part B (3 pos) If a reference counting garbage collection strategy is being used, what would be the reference count of the object at address $6172? Reference count of object at $6172 = Part C (8 pos) If the local variable whose value is the address $6120 is popped from the stack, which addresses will be reclaimed by each of the following strategies? If none, write none. Reference Counting: Mark and Sweep: Old-New Space (copying): 5

Problem 5 (3 parts, 30 pos) MIPS and C programming Part A (8 pos) Suppose the instruction jal Foo is executed which changes the values of the following registers to: Register Value $31 3216 PC 3620 What is the address of the first instruction of the subroutine Foo and what is the address of the jal Foo instruction? Subroutine Foo starts at address: Address of jal Foo instruction: Part B (12 pos) Suppose variables A, B, and C are of type and are stored in registers $1, $2, and $3. Write a MIPS code fragment that computes C = A * min(a, B);. Use only registers $0, $1, $2, and $3 and for maximum credit, use a minimal number of instructions and include comments. Label Instruction Comment Part C (10 pos) What does the following code fragment pr? A[10] = {1990, 3, 1992, 5, 1999, 1, 2001, 3, 2005, 1; B[10] = {1991, 2, 1993, 1, 1998, 7, 2002, 1, 2007, 6; i,j; for(i=1; i<10; i=i+2) { for (j=1; j<10; j=j+2) { if (A[i] == B[j]) { prf( C: %d, As: %d, Bs: %d.\n, A[i], A[i-1], B[j-1]); break; 6

Problem 6 (40 pos) Activation Frames The function Bar (below left) calls function Foo after completing code block 1. Write MIPS code that properly calls Foo. Include all instructions between code block 1 and code block 2. Note that code block 1 may change the values of the local variables (e.g., assume i can be any value from 0 to 2). Symbolically label all required stack entries and give their initial values if known (below right). Bar() { A[] = {9, 25, 27; i = 0; y = 5; (code block 1) A[1] = Foo(A, &y, A[i]); Bar s FP 9900 XXX XXX 9896 A[2] 27 9892 A[1] 25 9888 A[0] 9 9884 i 0 SP 9880 y 5 9876 9872 (code block 2) 9868 9864 9860 9856 label instruction comment # allocate activation frame # preserve bookkeeping info # compute A # push A # compute &y # push &y # compute A[i] by loading i, # scaling it, and adding it to # the base address of A # push A[i] jal Foo # call Foo # restore bookkeeping info # read return value # store return value in A[2] 7

MIPS Instruction Set (core) instruction example meaning arithmetic add add $1,$2,$3 $1 = $2 + $3 subtract sub $1,$2,$3 $1 = $2 - $3 add immediate addi $1,$2,100 $1 = $2 + 100 add unsigned addu $1,$2,$3 $1 = $2 + $3 subtract unsigned subu $1,$2,$3 $1 = $2 - $3 add immediate unsigned addiu $1,$2,100 $1 = $2 + 100 set if less than slt $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if less than immediate slti $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 set if less than unsigned sltu $1, $2, $3 if ($2 < $3), $1 = 1 else $1 = 0 set if < immediate unsigned sltui $1, $2, 100 if ($2 < 100), $1 = 1 else $1 = 0 multiply mult $2,$3 Hi, Lo = $2 * $3, 64-bit signed product multiply unsigned multu $2,$3 Hi, Lo = $2 * $3, 64-bit unsigned product divide div $2,$3 Lo = $2 / $3, Hi = $2 mod $3 divide unsigned divu $2,$3 Lo = $2 / $3, Hi = $2 mod $3, unsigned transfer move from Hi mfhi $1 $1 = Hi move from Lo mflo $1 $1 = Lo load upper immediate lui $1,100 $1 = 100 x 2 16 logic and and $1,$2,$3 $1 = $2 & $3 or or $1,$2,$3 $1 = $2 $3 and immediate andi $1,$2,100 $1 = $2 & 100 or immediate ori $1,$2,100 $1 = $2 100 nor nor $1,$2,$3 $1 = not($2 $3) xor xor $1, $2, $3 $1 = $2 $3 xor immediate xori $1, $2, 255 $1 = $2 255 shift shift left logical sll $1,$2,5 $1 = $2 << 5 (logical) shift left logical variable sllv $1,$2,$3 $1 = $2 << $3 (logical), variable shift amt shift right logical srl $1,$2,5 $1 = $2 >> 5 (logical) shift right logical variable srlv $1,$2,$3 $1 = $2 >> $3 (logical), variable shift amt shift right arithmetic sra $1,$2,5 $1 = $2 >> 5 (arithmetic) shift right arithmetic variable srav $1,$2,$3 $1 = $2 >> $3 (arithmetic), variable shift amt memory load word lw $1, 1000($2) $1 = memory [$2+1000] store word sw $1, 1000($2) memory [$2+1000] = $1 load byte lb $1, 1002($2) $1 = memory[$2+1002] in least sig. byte load byte unsigned lbu $1, 1002($2) $1 = memory[$2+1002] in least sig. byte store byte sb $1, 1002($2) memory[$2+1002] = $1 (byte modified only) branch branch if equal beq $1,$2,100 if ($1 = $2), PC = PC + 4 + (100*4) branch if not equal bne $1,$2,100 if ($1 $2), PC = PC + 4 + (100*4) jump jump j 10000 PC = 10000*4 jump register jr $31 PC = $31 jump and link jal 10000 $31 = PC + 4; PC = 10000*4 8