Difference between revisions of "CSC231 Homework 8 2010"

From dftwiki3
Jump to: navigation, search
(Submission)
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
<br />
 
<br />
  
<br />
+
<br />  
 
 
<br />
 
 
 
<br />
 
 
 
<br />
 
 
<tanbox>
 
<tanbox>
 
This homework is due Wednesday evening, 11/17/10, at midnight.  You can work on this assignment in pairs.
 
This homework is due Wednesday evening, 11/17/10, at midnight.  You can work on this assignment in pairs.
Line 38: Line 32:
 
* Your program should be called hw8.asm
 
* Your program should be called hw8.asm
 
* It should maintain the cells in a 1-dimensional array of size 70
 
* It should maintain the cells in a 1-dimensional array of size 70
* Each cell can be either dead or alive.  Dead cells are presented as spaces, life cells with a character of your choice.
+
* Each cell can be either dead or alive.  Dead cells are printed as spaces (or dots), life cells with a character of your choice.
 
* You are free to choose the initial population in the array
 
* You are free to choose the initial population in the array
 
* The rules are simple:
 
* The rules are simple:
** If a cell is alive in one generation, it will be dead the next.  The lifespan is finite.
+
** If a cell has 2 live neighbors in a generation, it dies in the next (overpopulation).
** If a cell is dead in one generation, but has only one alive neighbor, it will be alive in the next generation.  This correspond to a positive birth rate under preferred population size.
+
** If a cell has no live neighbors in a generation, it dies in the next (underpopulation).
 +
** If a cell has only one live neighbor in a generation, it either remains alive in the next, or is born in the next.
 
* Your program will print each generation one above the next, one line at a time.
 
* Your program will print each generation one above the next, one line at a time.
 
* Your program should print at least 20 generations, but no more than 60, so as to limit the size of the printout I'll hand back to you.
 
* Your program should print at least 20 generations, but no more than 60, so as to limit the size of the printout I'll hand back to you.
Line 66: Line 61:
 
     fate    db    0, 1, 0
 
     fate    db    0, 1, 0
  
if the number of neighbors is stored in ebx, for example, then mov al,[fate+ebx] will put the fate of the cell in al.  This is the type of trick you can use when you can't compare ebx to 0, 1 or 2.  
+
:if the number of neighbors is stored in ebx, for example, then mov al,[fate+ebx] will put the fate of the cell in al.  This is the type of trick you can use when you can't compare ebx to 0, 1 or 2.
  
 
=Submission=
 
=Submission=
  
 
     submit hw8 hw8.asm
 
     submit hw8 hw8.asm
 +
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
[[Category:CSC231]][[Category:Homework]]

Latest revision as of 18:44, 21 November 2010

--D. Thiebaut 13:36, 11 November 2010 (UTC)




This homework is due Wednesday evening, 11/17/10, at midnight. You can work on this assignment in pairs.


Game of Life in 1D

Assignment 1

Watch Conway talk about the Game of Life on YouTube (Parts 1 and 2).



Assignment 2

Read the page on Conway's Game of Life on Wikipedia. Great introduction.

Assignment 3

Your assignment is simple, and you have to write a program that you may have already written in one or two different languages before: [Conway's Game of Life]. The challenge this time, is that it must be done in assembly, using functions where parameters are passed through the stack and not via registers, and you have to write it without the compare instruction that would normally be used for this purpose (I'll show you a way around it).

Details

  • Your program should be called hw8.asm
  • It should maintain the cells in a 1-dimensional array of size 70
  • Each cell can be either dead or alive. Dead cells are printed as spaces (or dots), life cells with a character of your choice.
  • You are free to choose the initial population in the array
  • The rules are simple:
    • If a cell has 2 live neighbors in a generation, it dies in the next (overpopulation).
    • If a cell has no live neighbors in a generation, it dies in the next (underpopulation).
    • If a cell has only one live neighbor in a generation, it either remains alive in the next, or is born in the next.
  • Your program will print each generation one above the next, one line at a time.
  • Your program should print at least 20 generations, but no more than 60, so as to limit the size of the printout I'll hand back to you.
  • Below is an example generated by the applet on Garret Wilson's page, where the initial population was of size 6, distributed as follows: ..XXX.XXX....... where dots are dead, and Xs are alive.



1DGameOfLife.png



Requirements

  • Top-Down design
  • Use functions for everything. At least one for computing the new generation, one for printing it.
  • Functions cannot pass information through registers. Only via the stack!

Tricks

  • At some point you will have to compute the number of neighbors for each cell. A simple way to do this is to maintain your array of cells as a collection of integers that are either 0 or 1, 0 for dead, one for alive. Then when you want to compute the number of neighbors of cell Cell[i], you add together Cell[i-1] to Cell[i+1]. You will get 0, 1, or 2. You can create another array containing the rules of the game, so that you know how what the fate of the cell is by looking it up in the array.
    fate     db     0, 1, 0
if the number of neighbors is stored in ebx, for example, then mov al,[fate+ebx] will put the fate of the cell in al. This is the type of trick you can use when you can't compare ebx to 0, 1 or 2.

Submission

   submit hw8 hw8.asm