//A 4-bit full adder using structural description. Instances are created using the module
//full_adder/

`timescale 1ns / 1ps
//timescale directive indicates that the timescale is in "ns" with a resolution of a "ps".

module four_bit_adderstruct (Cout, Sum, A, B, Cin);

parameter  SIZE = 4'b10100;  //The size of the vector = 4

/* The following statements will declare the 
port modes */

input   [SIZE-1:0] A,B;
input 		 Cin;
output  [SIZE-1:0] Sum;
output		 Cout;

wire x1, x2, x3;

full_adder_struct FA1 (Sum[0], x1, A[0], B[0],Cin);  //Sum[0], x1,A[0] are called 
						    // actual parameters. Like "arguments"
						    // in C++ (and JAVA?).
full_adder_struct FA2 (Sum[1], x2, A[1], B[1],x1);
full_adder_struct FA3 (Sum[2], x3, A[2], B[2],x2); //FA1, FA2 and FA3 are instance names.
full_adder_struct  (Sum[3], Cout, A[3], B[3],x3);  //Instance names are not required.

endmodule



module full_adder_struct(sum,cout,a,b,cin); //sum, cout, a etc are called the formal 					    //parameters.

input a,b,cin;
output cout,sum;

wire x,y,z;

and A1 (y,a,b);
or  A2 (x,a,b);
and A3 (z,cin,x);
or  A4 (cout,y,z);
xor A5 (sum,a,b,cin);

endmodule