/*=======================================================================*/ /*IMLIG,1998.01.07,adder4.sfl, 4-bit full-adder example */ /*=======================================================================*/ /*-----------------------------------------------------------------------*/ /*interface declaration of 1-bit full-adder (submodule) */ /*-----------------------------------------------------------------------*/ 7 declare adder1 { 8 input a, b, cin; /*data terminals*/ 9 output s, cout; 10 instrin add; /*control terminal*/ 11 12 instr_arg add(a,b,cin); /*argument binding of add behavior*/ 13 }/*adder1*/ 14 /*-----------------------------------------------------------------------*/ /*module definition of 4-bit full-adder (top module) */ /*-----------------------------------------------------------------------*/ 18 module adder4 { 19 input A<4>, B<4>, CIN; 20 output S<4>, COUT; 21 instrin ADD; 22 23 adder1 ADDER0, ADDER1, ADDER2, ADDER3; /*module instantiation*/ 24 sel CARRY1, CARRY2, CARRY3; /*internal signal*/ 25 26 instruct ADD par{ /*definition of ADD behavior*/ 27 S= ADDER3.add(A<3>,B<3>,CARRY3).s /*S<3> ||= concatenation*/ 28 || ADDER2.add(A<2>,B<2>,CARRY2).s /*S<2>*/ 29 || ADDER1.add(A<1>,B<1>,CARRY1).s /*S<1>*/ 30 || ADDER0.add(A<0>,B<0>,CIN).s; /*S<0>*/ 31 COUT= ADDER3.cout; 32 33 CARRY3= ADDER2.cout; 34 CARRY2= ADDER1.cout; 35 CARRY1= ADDER0.cout; 36 }/*ADD*/ 37 }/*adder4*/ 38 /*-----------------------------------------------------------------------*/ /*module definition of 1-bit full-adder */ /*-----------------------------------------------------------------------*/ /* truth table of one bit full-adder ** input | output ** ---------------- ** a b cin | s cout ** 0 0 0 | 0 0 ** 0 0 1 | 1 0 ** 0 1 0 | 1 0 ** 0 1 1 | 0 1 ** 1 0 0 | 1 0 ** 1 0 1 | 0 1 ** 1 1 0 | 0 1 ** 1 1 1 | 1 1 */ 55 module adder1 { 56 input a, b, cin; 57 output s, cout; 58 instrin add; 59 60 instruct add par{ /*definition of add behavior*/ 61 s= a @ b @ cin; /* @= xor*/ 62 cout= (^a & b & cin) /* ^= not, &= and*/ 63 |( a & ^b & cin) /* |= or*/ 64 |( a & b & ^cin) 65 |( a & b & cin); 66 }/*add*/ 67 }/*adder1*/