next up previous contents
Next: Three-Input AND Gate Up: Examples Previous: Examples

Two-Input AND Gate

Since a two-input AND gate is at the lowest level of abstraction, the only encapsulated circuit elements will be two input ports and a single output port. A two-input AND class may be declared as follows:

class And2 : public Component
        And2(Connector &, Connector &, Connector &,
             ckt_time = 1L, char* = "And2");
        void     process(ckt_time);
        Input   I1, I2;
        Output  O1;

As required, the constructor is declared as taking three references to connector objects as parameters and the three ports are hidden in the private section of the class.

The constructor for the two-input AND gate is presented below. The delay and the name of the component are first passed to the Component base class constructor for initialization. The ports of the class are then connected with its primary inputs and outputs.

And2::And2(Connector &ci1, Connector &ci2, Connector &co1,
           ckt_time dly, char *name) :
        Component(dly, name),
        CONNECT(I1, ci1, "And2 I1"),
        CONNECT(I2, ci2, "And2 I2"),
        CONNECT(O1, co1, "And2 O1")        
{ }

Since the AND gate has no nested wires and no nested components, the description of the AND gate is finished. Its functionality is specified by redefining the virtual process() method. Describing the functionality of fundamental circuit components is presented in the next chapter.

When a two-input AND gate is actually instantiated and connected to primary input and output wires in the main C++ program, the data structure shown in Figure 3.1 is produced.

Figure 3.1: Two-Input AND Gate with External Wires

Donald Craig
Sat Jul 13 16:02:11 NDT 1996