Docsity

Instructions for Programming Assignments in LC-3 Assembly and C, Exams of Biomedical Engineering

Toggle sidebar
bg1
Page: 1 Name: ____________________________________________
1
ECE 190 Final Exam
Fall 2012
Tuesday, December 18th, 2012
Be sure your exam booklet has 4 double-sided pages.
Ask TA if you need paper for scratch work.
You are allowed three handwritten 8.5 x 11" sheets of notes.
This is a closed book exam. You may not use a calculator.
Absolutely no interaction between students is allowed.
Be sure to clearly indicate any assumptions that you make.
The questions have different level of difficulty. Budget your time accordingly.
Don’t panic, and good luck!
Instructions for accessing/working on the programming problems
Log into an EWS Linux machine.
Appendixes A and D from the textbook are provided for you on the desktop.
Open a terminal window. Check if directory finalexam exists.
Save your code in the files indicated by the problem statements. Do not rename the files.
We will not grade your problem if it is not saved as required.
We are NOT using a subversion repository for the exam. We will grade the saved files that
you leave in your finalexam directory.
Your code will be graded by an autograder. You may receive zero points if your code does
not assemble, does not compile, or does not behave as specified.
To begin work on problem X, use the cd command to get to the projectX directory.
To edit the file, type gedit givenfilename &
(Replace givenfilename with the name of the file where you will add your code.)
Save your work.
LC-3 Tools reference information
To assemble your code and produce the object file, type lc3as givenfilename.asm
To run the LC-3 graphical simulator, type lc3sim-tk givenfilename.obj
To run the LC-3 command-line simulator, type lc3sim givenfilename.obj
C Tools reference information
If Makefile is provided, use it for compiling the project code and follow the instructions
provided with the problem statement for running and testing your program
If no Makefile is provided, use gcc or clang compiler as follows:
To compile your code using clang compiler, type clang -ansi -Wall -lm <c file name>
To compile your code using gcc compiler, type gcc -ansi -Wall -lm <c file name>
To execute your code, type ./a.out
pf3
pf4
pf5

Partial preview of the text

Download Instructions for Programming Assignments in LC-3 Assembly and C and more Exams Biomedical Engineering in PDF only on Docsity!

ECE 190 Final Exam

Fall 2012

Tuesday, December 18th, 2012

Be sure your exam booklet has 4 double-sided pages.Ask TA if you need paper for scratch work.You are allowed three handwritten 8.5 x 11" sheets of notes.This is a closed book exam. You may not use a calculator.Absolutely no interaction between students is allowed.Be sure to clearly indicate any assumptions that you make.The questions have different level of difficulty. Budget your time accordingly.Don’t panic, and good luck! Instructions for accessing/working on the programming problems  Log into an EWS Linux machine.  Appendixes A and D from the textbook are provided for you on the desktop.  Open a terminal window. Check if directory finalexam exists.  Save your code in the files indicated by the problem statements. Do not rename the files. We will not grade your problem if it is not saved as required.  We are NOT using a subversion repository for the exam. We will grade the saved files that you leave in your finalexam directory.  Your code will be graded by an autograder. You may receive zero points if your code does not assemble, does not compile, or does not behave as specified.  To begin work on problem X, use the cd command to get to the projectX directory.  To edit the file, type gedit givenfilename & (Replace givenfilename with the name of the file where you will add your code.)  Save your work. LC-3 Tools reference information  To assemble your code and produce the object file, type lc3as givenfilename.asm  To run the LC-3 graphical simulator, type lc3sim-tk givenfilename.obj  To run the LC-3 command-line simulator, type lc3sim givenfilename.obj C Tools reference information  If Makefile is provided, use it for compiling the project code and follow the instructions provided with the problem statement for running and testing your program  If no Makefile is provided, use gcc or clang compiler as follows:  To compile your code using clang compiler, type clang - ansi - Wall - lm  To compile your code using gcc compiler, type gcc - ansi - Wall - lm  To execute your code, type ./a.out

Programming Problem 1 ( 25 pts): C to LC-3 Assembly Conversion

Convert the following function from C to LC-3. This function recursively traverses a linked list and counts the number of nodes in the list. int count_list(node *head) { if (!head) { return 0; } return 1 + count_list(head->next); } The linked list data node is defined as follows: typedef struct node { struct node *next; int data; } node; Remember that structures merely consist of simple data types where one element always comes after another in memory. That is if head points to an address of x 2004 , the next pointer address is contained within x 200 4 and data value is contained within x 200 5. Your program should be saved in finalexam/project1/count_list.asm file. The file already contains an LC-3 assembly implementation of MAIN function that calls count_list function. You should not modify MAIN function. data.asm file is provided for your convenience for testing. It contains a short hard-coded linked list consisting of 9 nodes. As you can see from MAIN’s implementation, list’s head node is stored starting at address x2004. To receive full credit, your program should correctly run in lc3sim (or lc3sim-tk) and should produce the correct output. You must use the run-time stack convention presented in the textbook for subroutine invocation. Your function does not need to save and restore the registers. You may not make any assumptions about the behavior of MAIN other than that it follows the runtime convention presented in the textbook. To test your count_list function using the provided MAIN and data.asm , assemble both print_list.asm and data.asm , load them in the lc3 simulator, set PC to x3000, and run it. Your code will be graded by an autograder for functionality of the count_list function as well as the correct construction of the activation record in the run-time stack. Consequently, you MAY NOT perform any optimizations that impact the contents of the stack. For example, ALL local variables used in the C function, if any, should be stored in the run-time stack appropriately. The local variables may NOT be stored locally in memory reserved by .FILL, .BLKW, etc. You may receive zero points if your code does not assemble or does not behave as specified.

Programming Problem 3 ( 20 pts): Testing and Debugging

In this assignment, you are required to find and fix errors and bugs in the provided program. The program implements functions that allow to add, find, and remove nodes in a doubly-linked list. There are three bugs, one in each of the following functions: struct test_struct* add_to_list(int val, bool add_to_end); struct test_struct* search_in_list(int val, struct test_struct **prev); int delete_from_list(int val); In addition, there is one syntax error that prevents the code from compiling without errors or warnings. You are required to find and fix it before finding the remaining bugs. main function and print_list function are provided for your convenience for testing purposes. Other functions are provided as necessary. Your fixed program should be saved in finalexam/project 3 /linkedlist.c. You may want to make a backup of this file before starting to modify it. You are welcome to use gdb , valgrind , or any other tools available on the system for debugging the code. The bugs may manifest themselves in unexpected behavior, segmentation fault, memory leak, or other undesirable side effects. Each bug can be fixed with a minor modification to just one line of the existing code, addition of a missing statement, removal of an instruction, or moving an instruction from one place to another in the source code. Extensive code modifications are not necessary and are not allowed.

Programming Problem 4 ( 35 pts): Problem Solving with Files and Arrays

In this assignment, you are required to implement a program for computing grade point average (GPA) based on the letter grades and credit hours stored in a file. The computed results should be stored into another file. Input file format Input file is student’s transcript. It contains the number of classes record followed by space- separated credit hours and letter grade records for each class. For example, the following file contains info about 4 classes: 4 3 A 1 B 3 C 3 F Item data structure typedef struct { int credit_hours; /* credit hours for a given class / char letter_grade; / corresponding letter grade / int grade_points; / corresponding grade points */ } class; Functions to implement class * read_transcript(char *file_name, int count); This function should read the number of classes record from the file with the supplied file_name and populate an array of class records with the data read from the file. Memory for the array of class records should be allocated dynamically.. Note that only the credit_hours and letter_grade fields need to be populated by this function. The function should return a pointer to the populated array of class records and the number of read records in count. If the function fails to read data from the file, it should return NULL and set count to 0. float calc_GPA(class tr, int count); This function should calculate grade points for each class as well as the overall GPA. The grade points for an individual class are computed by converting letter grade into a numerical value (A=4.00, B=3.00, C=2.00, D=1.00, F=0.00) and multiplying it by the credit hours. (Note that only letter grades A, B, C, D, and F are allowed in this assignment; all other grades, such as A+, I, W, etc. will not be used to test your program.) This value should be stored in the grade_points field for each class. GPA is computed by finding the total grade points and dividing them by the total credit hours attended. This value should be computed and returned by the function.