Académique Documents
Professionnel Documents
Culture Documents
Spring 2013
6th May, 2013
Problem
number
Max
25
25
25
25
Total
100
Score
Checked by
Appendixes A and D from the textbook are provided for you on the desktop.
Write 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 exam3 directory.
Your code will be at least partly 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 problemX directory.
To compile your code using clang compiler, type clang -Wall <c file name>
To compile your code using gcc compiler, type gcc -Wall <c file name>
13
11
17
HEAD
NULL
HEAD
NULL
Output:
data.asm file is provided for convenient testing. It contains a short hard-coded linked list consisting of 6
nodes. As you can see from MAINs implementation, lists head node is stored starting at address x2000.
To receive full credit, your program should correctly run in lc3sim (or lc3sim-tk) and should produce the
correct output. Your subroutine should expect the parameter head to be passed in R0, expect the
parameter n to be passed in R1, and should place the return value in R0. Your subroutine should save
and restore the registers using the callee-save convention. You may not make any assumptions about the
behavior or structure of MAIN beyond the parameter passing explained above.
To test your ROTATE_LIST subroutine using the provided MAIN and data.asm, assemble both leftrotation.asm and data.asm, load them in the lc3 simulator, set PC to x3000, and run it. You can inspect
the list at x2000 and the head pointer at label HEAD to see if the correct changes are made.
Your code will be graded by an autograder for functionality of the ROTATE_LIST subroutine. You may
receive zero points if your code does not assemble or does not behave as specified.
10
10
15
22
15
15
36
36
22
36
15
22
22
Problem 4. MicroSudoku
In MicroSudoku a 4x4 matrix is given with some empty cells and some cells with numbers in the set S={1,
2, 3, 4}. The player has to find numbers to fill the empty cells so that the following check conditions hold
(a) each number in S appears in every row, every column, and each of the four 2x2 sub-matrices, and (b)
none of the numbers repeat (in a row, column, or a submatrix). The figures below show an initial matrix,
the submatrices in bold lines, a solution for the initial matrix, and another matrix which has no solution.
4
1
Initial matrix A
4
4
1
You are given a function check() that checks the above conditions on a given board. Using this,
implement a recursive function solve(board) for solving MicroSudoku. The recursive algorithm for
solve(board) is as follows:
For every empty cell (i,j) in board
For each value v in S, assign v to board[i][j] . This gives rise to a new board.
Call solve on the new board.
If solve returns success (1) then return 1
If none of the numbers in S when assigned to board[i][j] pass the check, then make it an empty
cell again by resetting board[i][j] to 0 and return. (This will cause the algorithm to backtrack and
change the assignments to an earlier cell.)
If none of the cells are empty and the check() succeeds then return 1 else return 0.
Several initial matrices (or boards) are given as text files in the problem4/boards/. In addition
the following functions are given in problem4/main.c and you should not modify them:
load(board): Loads the 4x4 array called board[4][4] with the numbers from the specified
board text file which is passed as an argument to the main(). A zero (0) is loaded in the array for
empty cells.
print(board): Prints the board specified by board[4][4]. For an empty cell, it prints a dot.
check(board): Returns 1 if board is a solution of MicroSudoku, otherwise it returns 0 (e.g., if any
of the checks fail and/or the board is not filled). So, this function implements all the checks
stated above.
main(): This function loads the appropriate board, prints it, calls the solve function which you
will implement, and prints the result.
Compile: clang Wall main.c o main
Run: ./main boards/1.txt