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

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

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

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

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

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

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 One 4 February Your Name (please print clearly)

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

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

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, 10 pages Final Exam 9 December 2013

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

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

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

Assembly Programming

F. Appendix 6 MIPS Instruction Reference

MIPS Instruction Reference

Reduced Instruction Set Computer (RISC)

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

MIPS Reference Guide

Week 10: Assembly Programming

Computer Architecture. The Language of the Machine

Reduced Instruction Set Computer (RISC)

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

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

Computer Architecture. MIPS Instruction Set Architecture

TSK3000A - Generic Instructions

ECE 15B Computer Organization Spring 2010

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

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

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

MIPS Instruction Set

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

CS 61c: Great Ideas in Computer Architecture

The MIPS Instruction Set Architecture

MIPS%Assembly% E155%

SPIM Instruction Set

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

MIPS Instruction Format

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

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

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

CPS311 - COMPUTER ORGANIZATION. A bit of history

Programming the processor

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

Arithmetic for Computers

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

Mips Code Examples Peter Rounce

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

MIPS Assembly Language. Today s Lecture

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

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

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

Examples of branch instructions

M2 Instruction Set Architecture

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

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

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

Flow of Control -- Conditional branch instructions

CSc 256 Midterm 2 Spring 2012

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

CMPE324 Computer Architecture Lecture 2

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

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

CSc 256 Midterm (green) Fall 2018

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

CSc 256 Midterm 2 Fall 2011

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

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

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

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Concocting an Instruction Set

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Lec 10: Assembler. Announcements

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

Review of instruction set architectures

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

MIPS Assembly Language

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

INSTRUCTION SET COMPARISONS

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

CS61c MIDTERM EXAM: 3/17/99

Computer Architecture Experiment

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

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

CSc 256 Final Fall 2016

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

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

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

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

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

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

ece4750-parc-isa.txt

Adventures in Assembly Land

Review: MIPS Organization

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

Computer Organization & Design

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 40 20 25 30 40 175 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 cube, g, and h are pure functions that each return an eger with no side effects to other data structures. cube ( n) { return (n*n*n); g ( k) { h ( i, j) { slowcode( a, b) { t = 100; p = 1, s=0; do { if (s) p += t*cube(p); else p += h(s+a*t, p+a*t); prf("t:%d, p:%d\n",t,p); t++; while(t<g(p/256) + h(a, b)); return h(p, t); 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, 40 pos) MIPS and C Programming Part A (16 pos) Given two arrays A and B, of 64 egers, write a C fragment that loops through the two arrays and computes the average difference of the corresponding elements (i.e., A[i] B[i] for i from 0 to 63) and assigns the result to the variable avgdiff. The C fragment should also compute the minimum and maximum of the differences and assign them to the variables mindiff and maxdiff, respectively. For maximum credit, declare and initialize any necessary variables. NOTE: A and B can be any 64-element eger arrays, not just the example given. Pay careful attention to how you initialize mindiff and maxdiff the minimum difference could be greater than 0 and the maximum difference might be less than 0. A[64] = {-17, 2, 93, 9,... -14, 7; // given B[64] = {-19, 5, 93, 7,... -14, 8; // given avgdiff; mindiff; maxdiff; 3

Part B (24 pos) Write MIPS code for the fragment in Part A. Store the avgdiff computed in register $4, the mindiff in register $5, and maxdiff in register $6. For maximum credit use a minimum number of instructions. Label Instruction Comment A: B:.data.word -17, 2, 93, 9,... -14, 7.word -19, 5, 93, 7,... -14, 8.text given given 4

Problem 3 (4 parts, 20 pos) Short Answer Part A (4 pos) Write a single MIPS instruction that is equivalent to the original fragment. Assume little endian byte ordering. Original: lui $4, 0xFF00 lw $3, 1000($0) and $3, $3, $4 srl $3, $3, 24 Equivalent MIPS statement: Part B (4 pos) Suppose the instruction jal Foo is at instruction memory address 2020 and Foo is a label of an instruction at memory address 4040. When this instruction is executed, what changes occur to the registers. List all registers that are changed (both general purpose and special purpose) and give their new values. Register Value Part C (6 pos) For each of the following, write a single MIPS instruction to implement the C fragment? Assume variables A, B, C, and D are of type and are stored in registers $1, $2, $3, and $4. A = B & 7; C = D / 256; Part D (6 pos) Consider the MIPS code on the left which implements the array declaration and access on the right, where the variables Z, Y, X, and Value reside in $4, $5, $6, and $7 respectively. addi $1, $0, 48 mult $1, $4 mflo $1 sll $2, $5, 4 add $1, $1, $2 add $1, $1, $6 sll $1, $1, 2 sw $7, Array($1) Z, Y, X, Value; Array[ ][ ][ ]; Array[Z][Y][X] = Value; What does this code reveal about the dimensions of Array? Fill in the blanks in the array declaration with the size of each dimension that can be determined from the code. If a dimension cannot be known from this code, put a? in its blank. Assume a 32-bit operating system. 5

Problem 4 (4 parts, 25 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 16 6096 12 6128 8 6160 8 6004 33 6036 28 6068 4 6100 $6004 6132 60 6164 0 6008 40 6040 12 6072 55 6104 $6016 6136 75 6168 16 6012 12 6044 $6016 6076 8 6108 $6176 6140 16 6172 12 6016 0 6048 $6100 6080 6148 6112 12 6144 20 6176 $6132 6020 $6100 6052 $6116 6084 8 6116 $6032 6148 6046 6180 $6100 6024 $6088 6056 4 6088 4 6120 $6176 6152 80 6184 $6116 6028 8 6060 0 6092 40 6124 0 6156 26 6188 0 Part A (9 pos) Suppose the stack holds a local variable whose value is the memory address $6044. No other registers or static variables currently hold heap memory addresses. List the addresses of all objects in the heap that are not garbage. Addresses of Non-Garbage Objects: Part B (6 pos) If a reference counting garbage collection strategy is being used, what would be the reference count of the objects at the following addresses? Reference count of object at $6044 = Reference count of object at $6100 = Reference count of object at $6116 = Part C (6 pos) If the local variable whose value is the address $6044 is popped from the stack, which addresses from Part A will be reclaimed by each of the following strategies? If none, write none. Reference Counting: Mark and Sweep: Part D (4 pos) What benefit does reference counting garbage collection provide that mark and sweep garbage collection strategy does not provide? Benefit: 6

Problem 5 (2 parts, 30 pos) Doubly Linked Lists Consider a doubly linked list that is implemented using the following struct definitions. NOTE: These are the same as the structs used in Project 2-1, except the data field in llnode_t is of type and the DLinkedList has no size field. typedef struct llnode_t { data; struct llnode_t* previous; struct llnode_t* next; LLNode; typedef struct dll_t { struct llnode_t* head; struct llnode_t* tail; struct llnode_t* current; DLinkedList; Part A (12 pos) Assume a 32-bit system and consider the following create_dlinkedlst function: DLinkedList* create_dlinkedlist() { DLinkedList* newlist = (DLinkedList*)malloc(sizeof(DLinkedList)); newlist->head = NULL; newlist->tail = NULL; newlist->current = NULL; return newlist; A.1 What eger is passed to malloc when this function executes?. A.2 Which region of memory holds the variable newlist?. A.3 How much space (in bytes) is allocated for newlist in this region of memory? bytes. A.4 How much space (in bytes) is allocated for the return value of create_dlinkedlst? bytes. Part B (18 pos) Complete the C function Insert_Node_After that takes a poer to an LLNode and inserts it after the current node in the doubly linked list poed to by the input parameter DLL. Return 0 if the current node is NULL, otherwise return 1 (this code is already provided). Be sure to update the tail of DLL if N becomes the new tail. DLL s current field should not change. Insert_Node_After (LLNode *N, DLinkedList *DLL) { if(dll->current == NULL){ return 0; else{ return 1; 7

Problem 6 (2 parts, 40 pos) Consider the following C code fragment: typedef struct { Start; End; trip_info_t; TripAdvisor() { odometer = 981005; Gallons[] = {16, 6; trip_info_t TI; rate; Update(trip_info_t, [], *); TI.Start = 180; TI.End = 420; rate = Update(TI, Gallons, &odometer); return(odometer); Update(trip_info_t Trip, G[], *OD) { miles, MPG; miles = Trip.End Trip.Start; MPG = miles/g[1]; *OD += miles; return(mpg); Activation Frames Part A (18 pos) Suppose TripAdvisor has been called so that the state of the stack is as shown below. Describe the state of the stack just before Update deallocates locals and returns to TripAdvisor. Fill in the unshaded boxes to show TripAdvisor's and Update's activation frames. Include a symbolic description and the actual value (in decimal) if known. For return addresses, show only the symbolic description; do not include a value. Label the frame poer and stack poer. address description Value 9900 RA of TA s caller 9896 FP of TA s caller SP, TripAdvisor's FP 9892 RV 9888 9884 9880 9876 9872 9868 9864 9860 9856 9852 9848 9844 9840 FP: 9836 SP: 9832 8

Part B (22 pos) Write MIPS code fragments to implement the subroutine Update by following the steps below. Do not use absolute addresses in your code; instead, access variables relative to the frame poer. Assume no parameters are present in registers (i.e., access all parameters from Update s activation frame). You may not need to use all the blank lines provided. First, write code to properly set Update s frame poer and to allocate space for Update s local variables and initialize them if necessary. label instruction Comment Update: miles = Trip.End Trip.Start; label instruction Comment MPG = miles/g[1]; label instruction Comment *OD += miles; label instruction Comment return(mpg); (store return value, deallocate locals, and return) label instruction Comment 9

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 10