




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Cells, Debugging, Warmup, Linked Lists, Interaction, Implementing, Save Board Function
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





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
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:
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 ;
Implement the save board function in file.c in the mp directory. To receive any credit for this problem, the code must compile.
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
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
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 }.
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.
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.
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.
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.
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 }