Cells - Introduction to Engineering - Previous Exam, Exams of Introduction to Aerospace Engineering

Main points of this past exam are: Cells, Debugging, Warmup, Linked Lists, Interaction, Implementing, Save Board Function

Typology: Exams

2012/2013

Uploaded on 04/01/2013

ekan
ekan 🇮🇳

5

(1)

72 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 190 Final Exam
Wednesday, May 11th, 2011
Problem 1 (5 points): Warmup
Problem 2 (20 points): LC-3
Problem 3 (10 points): Debugging
Problem 4 (10 points): Linked lists
Problem 5 (15 points): Problem Solving
Be sure your exam booklet has 9 pages.
This is a closed book exam.
You are allowed four handwritten 8.5 x 11” sheets of notes.
Absolutely no interaction between students is allowed.
Don’t panic, and good luck!
Code must compile in order to receive credit! Students MUST compile
their code using the provided make commands. It is highly recommended
that you create backups of your code as you develop your solutions.
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Cells - Introduction to Engineering - Previous Exam and more Exams Introduction to Aerospace Engineering in PDF only on Docsity!

ECE 190 Final Exam

Wednesday, May 11th, 2011

Problem 1 (5 points): Warmup

Problem 2 (20 points): LC-

Problem 3 (10 points): Debugging

Problem 4 (10 points): Linked lists

Problem 5 (15 points): Problem Solving

  • Be sure your exam booklet has 9 pages.
  • This is a closed book exam.
  • You are allowed four handwritten 8.5 x 11” sheets of notes.
  • Absolutely no interaction between students is allowed.
  • Don’t panic, and good luck!
  • Code must compile in order to receive credit! Students MUST compile their code using the provided make commands. It is highly recommended that you create backups of your code as you develop your solutions.

Warmup (5 points)

For this problem, you will be implementing the save board function that transforms a board data structure into a binary file. The board file has the following binary format:

  • Each row of the board, in order, in the following format:
    • Cells of the row of the board in order, one byte per cell
    • A byte with value xFF
  • A sentinel byte with value xFF

The board data structure is just like the data structure you worked with in MP5, except that the cells are chars instead of an enumerated data type (in standard C, a char is 1 byte):

t y p e d e f s t r u c t { i n t rows ; /∗ Number o f rows i n the board ∗/ i n t c o l s ; /∗ Number o f columns i n the board ∗/ char ∗ c e l l s ; /∗ P o i n t e r to the board c e l l a r r a y ( row−major l a y o u t ) ∗/ } board ;

Implementation

Implement the save board function in file.c in the mp directory. To receive any credit for this problem, the code must compile.

Testing

To test, you must be in the mp directory. Run “make” to build the program. This will produce a test executable called “test save”, which when run will produce output files named output[0-2]. The expected outputs are in files named level[0-2]. For convenience, you can check if the output files match the expected ones by running “make test”.

Recall that you can view the contents of a binary file with the hexdump utility:

hexdump −C

Getting Started

After invoking the ’ece190’ script, you will find an lc3 directory in which you will find the files you need to edit. Specifically, ensure that records.asm, Makefile, and main.asm are present in this directory.

In the list.asm file, one test list is provided consisting of nodes with values { 0 }, { 3 }, { 6 }, and { 9 }. The addresses of these four nodes are x5000 (decimal 20480 ), x5003 (decimal 20483 ), x5006 (decimal 20486 ), and x5009 (decimal 20489 ) respectively. Feel free to make your own test case files by using list.asm as a template.

To compile your code or to test your code, you may use make and make test respectively. If your program gets stuck, hitting Ctrl+C will stop the simulator.

After compiling your program, you can manually test your code by loading (in this order): list.obj, records.obj, and main.obj in the lc3sim-tk or lc3sim. You may test the insertion of a new node by modifying the memory address with the label ELEMENT by invoking the mem ELEMENT command in the simulator. Running the main function will insert the node ELEMENT into the given list and print out the value, prev pointer, and next pointer of ELEMENT.

Running make test will perform three separate insertions on the sample list. Each insertion will be performed on a fresh list loaded from list.obj. For each given insertion value, you should verify that the prev and next pointers point to the expected nodes. For example, after inserting { 5 } into the sample list, the prev pointer should have the address of the node { 3 } and the next pointer should have the address of the node { 6 }.

Specifics

  • To receive any credit for this problem, the code must compile.
  • Assume this code is caller-save for R0-R4, which means the function does not need to save-restore them.
  • You must do only what is asked of you in each section of code to receive credit. Your program will be automatically graded by setting the PC address to the appropriate label and breaking at the next label to observe the changes to the LC-3 state machine.
  • Do not alter labels or comments already in the code!

Debugging (10 points)

In this assignment, you are asked to find and fix a bug in the provided code. The purpose of the given code is to create and destroy an array of balls. Further details about the individual functions can be found in the documentation comments in the code.

Getting Started

  • Invoke the ’ece190’ script
  • Execute ’cd debug’
  • Execute ’ls’ to verify that debug.c and Makefile are present
  • To compile the code, simply type ’make’.

Specifics

  • To receive any credit for this problem, the code must compile.
  • There is one bug in this code. You must fix it to receive any credit.
  • The bug can be fixed with only minor modifications of the code.
  • The bug is found in debug.c.
  • A blank main function is provided in main.c for debugging if you wish to use it.
  • Extensive code modifications are not allowed and will be penalized.
  • Do NOT change the given algorithm.

Problem Solving (15 points)

In this assignment, you will implement a function for performing erosion of a 2D image. The result of an image erosion is a new image of the same size as the original image with pixel values computed as the minimum value of all the pixels in the input pixel’s neighborhood.

Algorithm

Given an image I represented as an N × M array and a square erosion operator of size 3, the result of the erosion of image I by the erosion operator is an N × M image E whose pixels are computed as Ei,j = min − 1 ≤s≤ 1 − 1 ≤t≤ 1

{Ii+s,j+t}

where 0 ≤ i ≤ N − 1 is the row index and 0 ≤ j ≤ M − 1 is the column index. When computing the erosion, assume that image is zero-padded. That is, when pixel Ii+s,j+t falls outside the image (when i + s < 0, or i + s ≥ N , or j + t < 0, or j + t ≥ M ), assume its value is always set to 0.

Implementation Requirements

You are required to write the following function that implements the above algorithm:

v o i d i m e r o s i o n ( i n t ∗A, i n t ∗C, i n t N, i n t M) ;

In this function, the parameter A is a pointer to the array containing the two-dimensional image I. The parameter C is a pointer to the array for storing the final image E. Note that array A consists of N × M pixels and array C consists of N × M pixels. You can assume that both arrays are properly allocated and the input array is filled in with image data stored in row-major order. You are required to fill in the output array C with the eroded image data also stored in the row-major order.

You are also required to implement a helper function that computes an erosion at location (x, y):

i n t p o i n t e r o s i o n ( i n t ∗A, i n t N, i n t M, i n t x , i n t y ) ;

You are required to call this function within im erosion function to compute the pixel values of the resulting image.

Example Run

i n t A [ ] = { 1 , 1 , 1 , 1 , 1 , /∗ a 5 x 5 p i x e l s image ∗/ 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 5 , 5 , 5 , 5 , 5 , 2 , 2 , 2 , 2 , 2 } ; i n t C [ 2 5 ] ; /∗ a 5 x 5 image ∗/

i m e r o s i o n (A, C, 5 , 5 ) ; /∗ C = eroded image A ∗/

After this code is executed, image array C should be set to

{ 0 , 0 , 0 , 0 , 0 0 , 1 , 1 , 1 , 0 , 0 , 5 , 5 , 5 , 0 , 0 , 2 , 2 , 2 , 0 , 0 , 0 , 0 , 0 , 0 }

Getting Started

  • Invoke the ’ece190’ script.
  • Execute ’cd problem’.
  • Execute ’ls’ to verify that problem.c is present.
  • To compile the code, simply type ’make’.
  • To run the code, type ’./problem’ and input the necessary information.
  • To test the code using the above example, type ’make test’.

Specifics

  • To receive any credit for this problem, the code must compile.
  • To receive credit for point erosion function, the function must be used in im erosion function.