//=======================================
// ex6-3.7 Adder / Substrator with control circuit
module EX10_15( A, B ,en ,Cout , Sum);
input A,B,en ; // 1位元輸入
//en=0 Add , en=1 Sub
output reg Cout , Sum ; // Output 1位元輸出
always@ ( A,B,en ) begin
{Cout,Sum}= (en==0)?(A+B):(A-B);
end
endmodule
//=======================================
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
// Inputs
reg A,B,en;
// Outputs
wire Cout , Sum ;
// Instantiate the Unit Under Test (UUT)
// Adder / Substrator with control circuit
EX10_15 UUT (
.A(A),
.B(B),
.en(en),
.Cout(Cout),
.Sum(Sum)
);
initial begin
$monitor( A,B,en,Cout ,Sum);
//Apply inputs
en=1'b0;
A=1'b0; B=1'b0;
#100;
{A,B}=2'b01;
#100;
{A,B}=2'b10;
#100;
{A,B}=2'b11;
#100;
en=1'b1;
A=1'b0; B=1'b0;
#100;
{A,B}=2'b01;
#100;
{A,B}=2'b10;
#100;
{A,B}=2'b11;
#100;
end
initial begin
#800 $stop;
end
endmodule
//=======================================
沒有留言:
張貼留言