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

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

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, 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 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

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

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 19 September 2012

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

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

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

MIPS Instruction Reference

Reduced Instruction Set Computer (RISC)

F. Appendix 6 MIPS Instruction Reference

Week 10: Assembly Programming

Assembly Programming

Reduced Instruction Set Computer (RISC)

MIPS Reference Guide

Computer Architecture. The Language of the Machine

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

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

MIPS Instruction Set

SPIM Instruction Set

The MIPS Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture

TSK3000A - Generic Instructions

ECE 15B Computer Organization Spring 2010

CS 61c: Great Ideas in Computer Architecture

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

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

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

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

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

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

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

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

MIPS Instruction Format

Programming the processor

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

CPS311 - COMPUTER ORGANIZATION. A bit of history

CSc 256 Midterm (green) Fall 2018

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

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

Mips Code Examples Peter Rounce

M2 Instruction Set Architecture

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Computer Architecture Experiment

MIPS Assembly Language. Today s Lecture

MIPS%Assembly% E155%

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

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

Lec 10: Assembler. Announcements

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Arithmetic for Computers

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

CSc 256 Midterm 2 Spring 2012

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

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

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

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

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

CSc 256 Midterm 2 Fall 2011

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

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013

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

CSc 256 Final Fall 2016

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

Concocting an Instruction Set

Examples of branch instructions

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

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

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

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

Flow of Control -- Conditional branch instructions

INSTRUCTION SET COMPARISONS

CMPE324 Computer Architecture Lecture 2

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

MIPS Assembly Language

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Review: MIPS Organization

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

ECE 30 Introduction to Computer Engineering

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

Chapter 2A Instructions: Language of the Computer

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

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

CSc 256 Final Spring 2011

CS61c MIDTERM EXAM: 3/17/99

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

EE 109 Unit 8 MIPS Instruction Set

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

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

CS 61c: Great Ideas in Computer Architecture

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

Review of instruction set architectures

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

COMPUTER ORGANIZATION AND DESIGN

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 print) 1 2 3 4 total 25 25 25 25 100 1

Problem 1 (4 parts, 25 points) Complete the following C code by following the steps below: int Square(int x) return(x*x); int Cube(int y) return(exp(y, 3)); int Quad(int z) return(square(z)*square(z)); typedef int My_Math(int a, int lim, int b) { Function Pointers Walk(a, lim, ); /* part B */...rest of My_Math's body... int Walk(int Init, int Limit, ){ /* part C */ int i; for (i = Init; i<limit; i=s(i)) printf( %d\n, GlobalArray[i]); /* line P, part D */...rest of body of Walk... Part A (9 points) Create a local variable, called Stride, in My_Math that is a function pointer that points to Cube if b>100 and to Quad otherwise. Use a typedef to define the function pointer type. Part B (2 points) Pass this function pointer to the subroutine Walk as its third parameter. Part C (2 points) Complete the subroutine Walk by filling in type and name information for its third parameter which should be named S. Part D (12 points) Suppose Square, Cube, and Quad are defined in instruction memory starting at the following addresses: Square: 1000 Cube: 1200 Quad: 1600 The stack has the state shown below when My_Math is called. Complete the activation frames for My_Math and Walk and show the state of the stack after line P in Walk is executed twice. Symbolically label stack entries and give their values if they are known. a 2 lim 262144 b 105 SP & FP: 9900 RV N/A 2

Problem 2 (5 parts, 25 points) Heap Management Below is a snapshot of heap storage. The heap has been allocated contiguously beginning at 6000, with no gaps between objects. Heap management maintains a sorted free list to implement a best-fit strategy for reusing freed objects. The heap pointer is 6152 and the free pointer is 6064. addr value addr value addr value addr value addr value addr value 6000 12 6032 8 6064 6036 6096 8 6128 0 6160 0 6004 24 6036 6080 6068 4 6100 6052 6132 4 6164 0 6008 4 6040 10 6072 20 6104 16 6136 6032 6168 0 6012 16 6044 12 6076 16 6108 12 6140 0 6172 0 6016 12 6048 16 6080 6128 6112 152 6144 24 6176 0 6020 6008 6052 6032 6084 6004 6116 8 6148 0 6180 0 6024 2020 6056 6100 6088 4 6120 16 6152 0 6184 0 6028 28 6060 4 6092 6080 6124 24 6156 0 6188 0 Part A (4 points) Assuming the heap has been allocated contiguously beginning at 6000, with no gaps between objects, circle all object size words in the map above. Part B (6 points) List the address of the first data word in each object in the free list in order, starting with the head of the free list. Addresses of Objects on Free List (in order): Part C (3 points) Based on the free list created in part B, if an object of size 28 bytes is allocated, what address will be returned? How many bytes of slack (if any) will result? Address: Slack: Part D (6 points) Suppose the next instruction is free(ptr), where ptr = 6048. List all the changes to memory that will result: Address New Value Part E (6 points) Based on the free list after part D, if an object of size 22 bytes is allocated, what address will be returned? How many bytes of slack (if any) will result? Address: Slack: List all the changes to memory that will result: Address New Value 3

Problem 3 (7 parts, 25 points) Complete the following C code by following the steps below: typedef struct Med { float Temp; int HDL; int BMI; struct Med *Next; Med; Med *Records = NULL; void Add_Patient(float T, int C, int B){ Dynamic Allocation on Heap ; /* part B*/ if ( ){ /* part D */ printf( Error: Insufficient space. ); exit(1); ; /* part E*/ ; /* part E*/ ; /* part E*/ ; /* part F*/ ; /* part F*/ Part A (3 pts) Add a local variable called NewPatient to Add_Patient that is a pointer to a Med object. Part B (4 points) Allocate space for a Med structure using malloc and make NewPatient point to the object allocated. Be sure to include appropriate type casting to avoid type errors. Part C (4 points) How many bytes are allocated in Part B for the Med structure, excluding its size header? bytes Part D (3 pts) Fill in the test for whether malloc found enough space which controls the print statement. Part E (4 pts) Initialize the fields (Temp, HDL, BMI) of the newly allocated Med object to the values of the 3 input parameters (T, C, B, respectively). Part F (4 points) Push the newly allocated Med object onto the front of the list of Med objects pointed to by the global variable Records. Part G (3 points) Suppose a subroutine Delete_Records is implemented only by the statement: Records = NULL; What common memory problem would this create? 4

Problem 4 (4 parts, 25 points) Tile Puzzle Suppose you were given a C program P1-1.c that solved the tile puzzle assigned in Project 1. Recall that the tiles are stored in memory in row-column order and each tile is stored as a word of packed bytes, where each byte encodes the color of a triangle in the tile according to the following ordering: North: Byte 3 West: Byte 2 South: Byte 1 East: Byte 0 Part A (3 points) If you wanted to test the compiled program for the best case running time on a 5 by 5 grid, what value would you select for number of colors? Briefly explain why. #colors: Why? Part B (3 points) If you wanted to test the compiled program for the worst case running time on a 5 by 5 grid, what value would you select for number of colors? Briefly explain why. #colors: Why? Part C (10 points) Suppose register $5 contains the address of tile I in the puzzle and register $6 contains the row length (number of tiles in a row). Write MIPS code to branch to the label SouthOK when tile I's south triangle has the same color as one of the triangles in tile I's southern neighbor; otherwise, it should branch to NoFit. Assume tile I is not on the bottom row of the tile grid. Use a minimum number of static and dynamic instructions and modify only registers $1, $2, and $3. label instruction comment Part D (9 points) Write MIPS code to take the tile whose address is in $5, rotate it 90 degrees clockwise and store the result back in the address given in $5. Use a minimum number of instructions and registers. label instruction comment 5

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 6