Difference between revisions of "CSC231 Homework 7 Fall 2017"

From dftwiki3
Jump to: navigation, search
(Problem 2: Coding in C)
(Skeleton Program)
Line 146: Line 146:
  
 
   int N = atoi( argv[1] );
 
   int N = atoi( argv[1] );
   printf( "N = %d\n", N );
+
   printf( "Command line parameter = %d\n", N );
  
 
   return 0;
 
   return 0;

Revision as of 14:53, 13 November 2017

--D. Thiebaut (talk) 14:24, 9 November 2017 (EST)



This assignment is due on 7/20/17 at 11:55 p.m.






Problem 1: Life on a new level


For this problem you have to implement a more interesting game of life. Take a look at a demo of the solution program. You will understand right away what your program will have to do:

cs231a@aurora ~/handout $ ./hw7a
> 0
> @@

cs231a@aurora ~/handout $ ./hw7a
> 1 
> @      @       @
@      @       @

cs231a@aurora ~/handout $ ./hw7a
> 2
> @           @            @
@           @            @
 @         @ @          @ 

cs231a@aurora ~/handout $ ./hw7a
> 10
> @                @                  @
@                @                  @
 @              @ @                @ 
  @            @   @              @  
 @ @          @ @ @ @            @ @ 
    @        @       @          @    
   @ @      @ @     @ @        @ @   
  @   @    @   @   @   @      @   @  
 @ @ @ @  @ @ @ @ @ @ @ @    @ @ @ @ 
        @@               @  @        
       @@@@             @ @@ @


Explanations


  • The program prompts for 2 pieces of information: an integer, which can be 0 or positive, and a string of spaces and '@' characters.
  • The integer represents the number of generations we want to have our dish of cells go through. 0 means nothing gets printed. 1 means the original generation entered by the user is shown. 2 or more indicates that the program goes through a loop and evolves the cells in the dish.
  • The string can be as long as what _getString allows, which is 1000 characters. However, for this assignment, we will assume that the string of live and dead cells entered by the user will never be more than 100 characters. It also means that your program will be tested only with strings of no more than 100 cells.


Requirements


  • Your program should NOT any loop instructions. Use the cmp instruction and conditional jumps to control the different loops.


Additional Information


Program Developed in Class


     getcopy  GameOfLifeClassV2.asm 


Getting an int from the keyboard


Use _getInput, which is part of the 231Lib.asm library.

        call    _getInput
        mov     dword[numGen], eax


Getting a string from the keyboard


We've used it before: _getString. It returns the address of the string in ecx, and the number of chars entered in edx. _getString has its own buffer of 1000 characters in which is saves the string. It will return the address of this buffer in ecx.

Submission


  • Save your program in a file called hw7a.asm and submit it to Moodle.
  • Document your code well!



Problem 2: Coding in C


  • Write a C program called hw7b.c that uses loops to print the first N lines of the Pascal triangle.
  • Examples with the solution program:


for n in 0 1 2 5 10 ; do echo "n =$n" ;  ./hw7b $n; echo ""; done
n =0

n =1
   1 

n =2
   1    0 
   1    1 

n =5
   1    0    0    0    0 
   1    1    0    0    0 
   1    2    1    0    0 
   1    3    3    1    0 
   1    4    6    4    1 

n =10
   1    0    0    0    0    0    0    0    0    0 
   1    1    0    0    0    0    0    0    0    0 
   1    2    1    0    0    0    0    0    0    0 
   1    3    3    1    0    0    0    0    0    0 
   1    4    6    4    1    0    0    0    0    0 
   1    5   10   10    5    1    0    0    0    0 
   1    6   15   20   15    6    1    0    0    0 
   1    7   21   35   35   21    7    1    0    0 
   1    8   28   56   70   56   28    8    1    0 
   1    9   36   84  126  126   84   36    9    1


Skeleton Program


  • Play with the following program to see what it does, and then build up from there.


/*                                                                                                                      
  hw7b.c                                                                                                                
  A skeleton program to get you started.                                                                                
*/
#include <stdio.h>
#include <stdlib.h>


int main( int argc, char *argv[] ) {
  if ( argc<= 1 ) {
    printf( "Syntax %s N\n", argv[0] );
    printf( "where N is the number of rows of Pascal triangle to be printed\n" );
    return 0;
  }

  int N = atoi( argv[1] );
  printf( "Command line parameter = %d\n", N );

  return 0;
}








...