Goals

  • Learn about circuits.

  • Learn about event-driven simulation.

  • See a typical use for a queue.

  • Learn about organizing and coding a medium size program.

  • Provide an extra-credit opportunity to atone for a low score on a previous assignment.

  • Checking your work and hints

  • Significant hints are available here. Novices will definitely want to use these to get started.

  • The directory ftp.cs.princeton.edu/pub/cs126/circuit contains a number of circuit data files (.txt extension) that you can use to test out your program. Note that buzzer.txt describes a sequential circuit that never "settles down" - set the input to 1, then to 0 and watch what happens!

  • Windows users can use the program simulator126.exe to check your work.

  • You program may assume that the maximum number of gates is 128, and that the maximum number of outputs for any one gate is 16. If you are using Windows and lcc, you may need to increase the stack size (space available for local variables and function parameters) or your program will crash without providing a clue as to the reason. To accomplish this, either decrease the size of MAX_GATES and MAX_OUTPUTS in CIRCUIT.h when testing, or increase the available stack size by compiling with:
    lcc126 simulator.c circuit.c queuearray.c -stack-commit 131072
    

  • Submission and readme
  • Submit your files via courseinfo.cs.princeton.edu as usual. We require that main() function be located in simulator.c, but you can also submit auxiliary files as needed. Submit all source and header files needed to compile your program (including any that we supply in the hints page). We will compile your program with the following command:
    gcc126 *.c
    

  • The input of your program should be exactly as described in the assignment. Your program will be tested automatically, so deviating from these instructions will result in a significant penalty.

  • The circuit description will be read from a file corresponding to the command line input.

  • The values of the circuit inputs will be read in from standard input, and the values will either be 0 or 1.

  • After each simulation, the user enters 'q' to quit the program, and any other letter to continue.
  • The readme.txt file should contain the following information. Here is a template readme file:

  • Name, precept number, high level description of code, any problems encountered, and whatever help (if any) your received.

  • Extra credit

  • Create a data file (in the given format) for an interesting circuit, perhaps one from the course packet. Give it an appropriate name, e.g., 8bitadder.txt or master-slave.txt.

  • Write a program that reads in a circuit and determines whether or not it is a combinational circuit. If it is, then it should print a truth table of the combinational circuit.
    % a.out majority3way.txt
    x y z  f
    --------
    0 0 0  0
    0 0 1  0
    0 1 0  0
    0 1 1  1
    1 0 0  0
    1 0 1  1
    1 1 0  1
    1 1 1  1
    
    % a.out srflipflop.txt
    Not a combinational circuit.
    
    % a.out buzzer.txt
    Not a combinational circuit.
    
    Important: The main() function must be located in the file extra.c. We will compile your program with the command gcc126 *.c, after removing the file simulator.c.



  • Kevin Wayne