09.07.2015 Views

6. Digital simulation in Alecsis - LEDA

6. Digital simulation in Alecsis - LEDA

6. Digital simulation in Alecsis - LEDA

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>6.</strong> <strong>Digital</strong> <strong>simulation</strong> <strong>in</strong> <strong>Alecsis</strong> 85• creat<strong>in</strong>g new logic truth tables,• overload<strong>in</strong>g of appropriate logic operators, to accept l<strong>in</strong>ks of the new type• if model cards are to be used, declarations of model class and def<strong>in</strong>ition of methods are necessary.In this way basis for <strong>simulation</strong> with new logic system is created, which can be used for creation of models.<strong>6.</strong>1.1. Systems of statesSystem of state of a simulator describes legal states of a digital simulator. Total number of these states iscalled the card<strong>in</strong>al number of the simulator. Many simulators have a built-<strong>in</strong> system of state. <strong>Alecsis</strong> does not havesuch a system, and it needs to be def<strong>in</strong>ed before the <strong>simulation</strong> (often used systems are available <strong>in</strong> the library).You need to use enumeration types to def<strong>in</strong>e the system of state. To allow for representations of digitalwords (vectors), system of state needs to be def<strong>in</strong>ed with characters as symbols. Examples are:typedef enum { 'x', '0', '1' } three_t; //system with 3 statestypedef enum { 'x', '0', '1', 'z' } four_t; //system with 4 statestypedef enum { ' '=void, '_'=void,'x', 'X'='x', '0', '1', 'z', 'Z'='z'} four_t;The last example def<strong>in</strong>es a type with 4 states, two types of separators for enumeration str<strong>in</strong>gs, and is case<strong>in</strong>sensitive.Enumeration types <strong>in</strong> AleC++ occupy 1 byte (char), tak<strong>in</strong>g that the <strong>in</strong>dexes of symbols are <strong>in</strong> range -128to 127, otherwise they take 2 bytes.Term "system of states" is used conditionally, s<strong>in</strong>ce the construct typedef merely def<strong>in</strong>es a new name fora enumeration set. Thus, an unlimited number of different "systems of states" can exist on the global levelsimultaneously, tak<strong>in</strong>g the names are different.The order of symbols <strong>in</strong> the set is important for three reasons:• If sets are non-<strong>in</strong>itialized, values are given as <strong>in</strong> C/C++ - start<strong>in</strong>g from value 0 for the first signal.• Order of states is important for creat<strong>in</strong>g truth tables of logic functions;• Signals (digital l<strong>in</strong>ks) that are not <strong>in</strong>itialized, have the start<strong>in</strong>g value that is the first symbol <strong>in</strong> the set. In ourexample, all signals <strong>in</strong> the circuit of type three_t and four_t that are not <strong>in</strong>itialized will have start<strong>in</strong>gstate 'x', s<strong>in</strong>ce 'x' is the first symbol <strong>in</strong> the set (separators do not count). Therefore, undef<strong>in</strong>ed state 'x'should be always the first symbol, as it is usual to treat non-<strong>in</strong>italized signal as undef<strong>in</strong>ed when the <strong>simulation</strong>beg<strong>in</strong>s.<strong>6.</strong>1.2. Truth tablesAleC++ has basic b<strong>in</strong>ary logic operators needed for logical <strong>simulation</strong>. However, they accept <strong>in</strong>tegeroperands, not enumeration ones. This means that for every new system of state we have to def<strong>in</strong>e truth tables for alloperators. Truth tables for unary operators are vectors of length N, for b<strong>in</strong>ary -- matrices NxN, where N is thenumber of states <strong>in</strong> the actual system of states (the card<strong>in</strong>al number).const three_t nottab[] = { 'x', '1', '0' };// x 0 1const three_t andtab[][3] = { { 'x', '0', 'x' }, // x{ '0', '0', '0' }, // 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!