






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Spring 2012
Friday, May 4 th^ , 2012
Name: NetID: ___________________________
Lab Section (please check the box):
DCL 440 DCL 520 9:00 AM [ ] AD4 [ ] AD 10:00 AM [ ] ADA 12:00 PM [ ] AD5 [ ] AD 1:00 PM [ ] AD3 [ ] AD 2:00 PM [ ] AD 3:00 PM [ ] AD1 [ ] AD
Be sure your exam booklet has 7 problems, on 11 pages. This is a closed book exam. You may not use a calculator or any other electronics (other than your exam computer). You are allowed three handwritten 8.5 x 11" sheet of notes. Absolutely no interaction between students is allowed. Be sure to fully read each question before answering. Do your best!
Additional Notes:
Given the following logic circuit diagram:
Part A: Complete the truth table for the circuit output F.
Part B: Write the logic equation (Boolean expression) implemented by the circuit.
Write your answers in the file problem1.txt
Files you are given in the problem1 directory:
problem1.txt : Write your answers here. Only answers in this file will be considered for credit.
During the FETCH phase of the instruction cycle, bits are transferred among the PC, IR, MAR, and MDR registers.
Identify the sequence of transfers and state what the bits represent by filling in the blanks labeled below. (The labels of these blanks correspond to the labels in your problem3.txt file)
Step 1: Bits are transferred from (A) to (B). Those bits represent (C). Step 2: Bits are transferred from (D) to (E). Those bits represent (F).
Files you are given in the problem3 directory:
problem3.txt : Write your answers here. Only answers in this file will be considered for credit.
Assume the following variables are stored in memory:
Memory Address
Memory Contents x4000 alpha x4001 beta x4002 gamma x4003 delta
Where alpha, beta, gamma, and delta are values in memory (think of them as variables). At the beginning of each part below, assume that the register R5 contains the value x.
For each part of this problem, you are given a segment of LC-3 Code. Use the code along with the information above (including the variable names defined in the table above) to write the corresponding C code.
Part A) Write the C code that corresponds to the following LC-3 instructions: LDR R0, R5, # LDR R0, R0, # LDR R1, R5, # NOT R1, R ADD R1, R1, # ADD R1, R1, R STR R1, R5, #
Part B) Write the C code that corresponds to the following LC-3 instructions: LDR R0, R5, # BRnz # ADD R0, R0, # ADD R0, R0, # STR R0, R5, #
Part C) Write the C code that corresponds to the following LC-3 instructions: LDR R0, R5, # ADD R1, R0, # LDR R2, R5, # ADD R2, R2, R STR R2, R5, #
Files you are given in the problem4 directory:
problem4.txt : Write your answers here. Only answers in this file will be considered for credit.
Write the function ShuffleMerge which, given two linked lists, merges their nodes together to make one list. These nodes are merged alternately between the two lists, starting with list 1. If either list runs out, all the remaining nodes should be taken from the other list. For example, ShuffleMerge() with [1, 2, 3] and [7, 13, 1, 4] as inputs should yield a third list [1, 7, 2, 13, 3, 1, 4].
Each node of the list contains an integer and a pointer pointing to the next element of the list, as defined by the following structure: typedef struct node_t { int data; struct node_t *next; } node;
The function definition is given as node ShuffleMerge(node list1, node* list2)** where list1 points to the head of the first list, list2 points to the head of the second list, and the return value points to the head of the resultant list.
Important Notes: The input lists can be empty or can contain one or more elements. If the first list is not empty, then the first element of the resultant list should be the first element of the first list. If both lists are empty, then the return value will be a null pointer. Your code will not perform any dynamic memory allocation. The nodes already exist in memory (if the lists are not empty); your code only needs to modify the pointer values to merge the lists as specified. Example
List1:
List2:
Result:
Implementation Details You are given the following files in your problem6 directory: shuffle_merge.c : Contains the ShuffleMerge function that you will implement. main.c : Contains the main function with one sample test case. You may modify this to perform any tests you desire. shuffle_merge.h : Contains the interface for the ShuffleMerge function. This includes all necessary function declarations and libraries. DO NOT modify this file Implement the functions in shuffle_merge.c and perform tests with main.c as necessary. You may NOT add any additional libraries (i.e., the math.h library) to your code.
To compile your code, run the provided compile script in your home directory: ./compile
If compilation is successful, a binary executable called "ShuffleMerge" will be produced. To run it, type ./ShuffleMerge
Check that the output values from your program are correct. Your code will be graded by an autograder for functionality. You may receive zero points if your code does not compile or behave as specified.
HINT OPTION: If you view the hint for this problem, the maximum amount of points you can earn on this problem is 13 points. To view the hint, type ./hint from your problem6 directory.
Write the helper functions for a program that converts a graph from array representation to linked list representation.
Background
A graph is a data structure that consists of a collection of nodes and the edges that connect those nodes. A directed graph has edges that are unidirectional, meaning that an edge is directed from one node to another. For example, in the example graph, there is an edge from D to B, but there is in no edge in the reverse direction (from B to D).
Array representation of a graph
The example graph can be represented using an adjacency matrix (2-D array). A, B, C, and D are characters that represent the nodes (“node_character” field in the struct below).
To this node: A B C D A 0 1 0 1 B 0 0 0 0 C^0 1 0 D 0 1 1 0
Linked list representation of a graph
Alternatively, the example graph can be represented using a linked-list-like representation. There is one vertex structure for each node in the graph (see the leftmost nodes below). The vertex structures are connected in a vertex linked list (shown from top to bottom).
Each vertex structure also contains a pointer to a neighbor linked list (shown from left to right) that contains the neighbor nodes (i.e., the graph nodes to which there is a directed edge from the vertex node).
For example, there are directed edges from node A to nodes B and D, so the ‘A’ vertex node contains a pointer to a neighbor linked list that contains a neighbor node for B and a neighbor node for D.
The end of each linked list is denoted with a NULL pointer value.
Indicates an edge from A to B
Indicates NO edge from B to A
From this node:
To compile your code, run the provided compile script in your home directory: ./compile
If compilation is successful, a binary executable called "graph" will be produced. To run it, type ./graph
To check whether you have freed all the allocated memory, run the script “check_memory” :
./check_memory
The script runs a valigrind command, and your output should look like this:
==5665== HEAP SUMMARY: ==5665== in use at exit: 0 bytes in 0 blocks ==5665== ==5665== All heap blocks were freed -- no leaks are possible ==5665==
Check that the output values from your program are correct. Your code will be graded by an autograder for functionality. You may receive zero points if your code does not compile or behave as specified.
HINT OPTION: If you view the hint for this problem, the maximum amount of points you can earn on this problem is 13 points. To view the hint, type ./hint from your problem7 directory.
C language problems: