Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi!! I m trying to genrate truth table for latches and flip flopsso for that I hav following table in a file which i Grep :
CP EN Qn-1 Qn 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1
and output is = CP * Qn input are CP and EN so I have to get expresion for Qn from above the evaluate output, to gerate the truth table. can any one help me with this!!!

Replies are listed 'Best First'.
Re: solving Flip Flop equations in perl
by JavaFan (Canon) on May 05, 2009 at 11:47 UTC
Re: solving Flip Flop equations in perl
by Marshall (Canon) on May 05, 2009 at 19:07 UTC
    In something like C or ASM, the obvious way to do this would be to encode the 3 input bits into an index into an array with 8 items. The value of that array would be Qn.

    In Perl that is also possible. However using a hash table representation might be better for more complex situations than this. You can encode the inputs "$CP$EN$Qprev" as a hash key. $Qnext = $table{"$CP$EN$Qprev"}; etc....

    In your case, this is a hardware thing that will produce 0,1 for any combination of inputs. When building a software state table, this hash approach allows us to deal with very sparse arrays and also deal specially with the "hey, this shouldn't happen case". Of course in complex hardware state tables, you will have to think about these "hey, this shouldn't happen case" and make sure that your state machine doesn't "dead end" into an infinite loop and so you have to have a better answer than an error message that says "program error"!

    Anyway consider a hash table representation.