



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!




Copyright © Orly Alter 2008 Bring Original & One Copy Last Name: ______ First Name: ______ Midterm Instructions:
a. Algorithm Design and Flowcharts, b. Coding Conditional Logic Operations and Iterations, c. Computation Space and Time, d. Code Testing and Debugging, and e. Simulating Cellular Automata.
Copyright © Orly Alter 2008 Bring Original & One Copy
a. Draw a logic circuit that implements the three-input AND gates using two-input AND gates. Explain the circuit in a sentence (5%).
Write a program for the LC-3 that implements this logic circuit and performs a bitwise three-input AND of R0=A, R1=B and R2=C, storing the result in R3=AND(A,B,C), as follows:
b. Draw a flowchart of the three- input AND algorithm. Reminder: Opposite are some common flowchart symbols (10%).
b. c. Convert your flowchart into a line-by-line detailed code. Specify address, instruction and comments as in the example below (15%): Address Instruction Comments X3000 1 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 R1 NOT(R3)
d. Now, summarize the truth table of the three-input AND with a single conditional statement (IF), as follows (5%): If
Write a program for the LC-3 that implements this conditional statement and performs a bitwise three-input AND of R0=A, R1=B and R2=C, storing the result in R3=AND(A,B,C), as follows:
Copyright © Orly Alter 2008 Bring Original & One Copy
Write a program that simulates this universe and its evolution, in the following steps: a. Write LC-3 code that inputs the initial states of the cells A, B, C and D into registers R0, R1, R2 and R3 respectively. Specify address, instruction and comments as in the example in Question 1(c) above (5%). b. Convert the rules of the game above into an algorithm that uses the input states of A, B, C and D, that are stored in R0, R1, R2 and R3, to compute the next state of A, store it in R4, and output it to memory address x3100. Draw a flowchart of this algorithm (20%). c. Convert your flowchart into a line-by-line LC-3 code. Specify address, instruction and comments (20%). d. Write your code in the LC-3 simulator, and take a screen shot of it (5%). e. Test and debug your code by using it to evaluate the truth table for the first update of A, and fill-in the table below based on the output of your code (10%): Inputs Output A 0 B 0 D 0 A 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
Copyright © Orly Alter 2008 Bring Original & One Copy
f. Write additional code lines that repeat this computation for the next states of B, C and D, and output the results to x3101, x3102 and x3103, respectively. Specify address, instruction and comments (20%). g. Finish the computation of the first update of all four cells with a piece of code that reads the content of x3100, x3101, x and x3103 into R0, R1, R2 and R3, respectively. Specify address, instruction and comments (5%). h. Write your code in the LC-3 simulator and take a screen shot of it. Test and debug your code for updating B, C and D, and explain how you do that (10%). i. Now that each cell has been updated once, designate R5 as a counter, and create a loop that repeats the updating 12 times and then exits the program (15%). j. Write your complete code in the LC-3 simulator and take a screen shot of it. Test and debug your code for the loop, and explain how you do that. Hint: You could follow the value of any one variable as it gets updated (10%). k. Use your program to play the four-cells game of life with the initial conditions below. Fill-in the updates of the first, second, third, fourth and 12th iterations. Which of these initial conditions leads to oscillations in the states of the four cells (30%)?
0th 1st 2nd 3rd 4th 12th
A 0 B 0 A 1 B 1 A 2 B 2 A 3 B 3 A 4 B 4 A 12 B 12 D 0 C 0 D 1 C 1 D 2 C 2 D 3 C 3 D 4 C 4 D 12 C 12
Copyright © Orly Alter 2008 Bring Original & One Copy
d. Convert your flowchart into a line-by-line LC-3 code. Specify address, instruction and comments as in the example in Question 1(c) above (20%). e. Compare this algorithm with the one of Question 2(c) in terms of computation space: Which one requires more registers to be implemented (5%)? f. Compare the two different algorithms in terms of computation time: Which one requires more steps, that is, code lines (5%)?