Docsity

Take Home Project - Introduction to Computing | BME 303, Study Guides, Projects, Research of Biology

Toggle sidebar
bg1
BME303 Midterm #2 Due Apr 15, 2008
Copyright © Orly Alter 2008 Bring Original & One Copy
1
Last Name: ______ First Name: ______
Midterm Instructions:
1. This midterm is a take home project for a total of 360%.
2. Each midterm must be stapled [50% score deducted otherwise].
3. Use this page as a cover.
4. Show details of your work, and explain in words, except in the most obvious cases.
5. Your work must be neat and clear.
LC-3 Code Instructions:
1. For all problems use x3000 as the starting address.
2. Last line of code is a TRAP instruction and is: xF025.
3. “Use Set Value” means just double click on the location and type the value. (Everything
else is done using LC-3 binary instructions.)
4. Your code should be well commented. (Follow the commenting style of the code
examples provided in class and in the textbook.)
Machine Language Programming
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.
1. Three-Input AND (70%):
The three-input AND is defined by the truth table:
A
B
C
AND(A,B,C)
0
0
0
0
0
0
1
0
0
1
0
0
0
1
1
0
1
0
0
0
1
0
1
0
1
1
0
0
1
1
1
1
pf3
pf4
pf5

Partial preview of the text

Download Take Home Project - Introduction to Computing | BME 303 and more Study Guides, Projects, Research Biology in PDF only on Docsity!

Copyright © Orly Alter 2008 Bring Original & One Copy Last Name: ______ First Name: ______ Midterm Instructions:

  1. This midterm is a take home project for a total of 360%.
  2. Each midterm must be stapled [50% score deducted otherwise].
  3. Use this page as a cover.
  4. Show details of your work, and explain in words, except in the most obvious cases.
  5. Your work must be neat and clear. LC-3 Code Instructions:
  6. For all problems use x3000 as the starting address.
  7. Last line of code is a TRAP instruction and is: xF025.
  8. “ Use Set Value ” means just double click on the location and type the value. (Everything else is done using LC-3 binary instructions.)
  9. Your code should be well commented. (Follow the commenting style of the code examples provided in class and in the textbook.)

Machine Language Programming

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.

  1. Three-Input AND (70%): The three-input AND is defined by the truth table: A B C AND(A,B,C) 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1

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 , then <output 1>, otherwise <output 2>.

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

  1. “Survival:” If at least one of its neighbors is alive, a living cell goes on living.

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

0 0 A 12 B 12

0 0 C 12 D 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%)?

  1. The Game of Life as a Double-Loop Program (60%): a. Write LC-3 code that inputs the initial states of the cells A, B, C and D into memory addresses x3100, x3101, x3102 and x3013, respectively. Specify address, instruction and comments as in the example in Question 1(c) above (10%). Redesign your algorithm for computing the first update of A so that it takes as an input only three variables: One is the initial state of A (from memory address x3100), and the other two are the initial states of its neighbors B and D (from addresses x and x3103, respectively). You could use either the algorithm of Question 2(c) or that of Question 3(c): b. Code your algorithm in a line-by-line LC-3 code. Specify address, instruction and comments (10%). c. Design a loop that would count from 1 to 4, in each count computing the update of a different cell, from A to D, and code it in LC-3 code (30%). d. Compare this algorithm with the one of Question 2(g) in terms of computation space and time: Which one requires more registers? Which one requires more code lines (5%)? e. What advantage does this algorithm has over the one of Question 2(g), irrespective of computation space and time (5%)?