Question

In: Computer Science

create a test bench for the following code: module signed_mult (out, clk, a, b); output [15:0]...

create a test bench for the following code:

module signed_mult (out, clk, a, b);
output [15:0] out;
input clk;
input signed [7:0] a;
input signed [7:0] b;
reg signed [7:0] a_reg;
reg signed [7:0] b_reg;
reg signed [15:0] out;
wire signed [15:0] mult_out;
assign mult_out = a_reg * b_reg;
always@(posedge clk)
begin
a_reg <= a;
b_reg <= b;
out <=mult_out;
end
endmodule

Solutions

Expert Solution

Ans:

The testbench:

// Code your testbench here
// or browse Examples
module test();
reg clk;
reg signed [7:0] a,b;
wire signed [15:0] out;
integer i;
signed_mult m1(out,clk,a,b);
initial
begin
clk=0;
#2
for(i=0;i<=5;i++)// the number can be incremented and -negative numbers can be added as well
begin
#4 a=i;b=i;
if(out != a*b)
begin
$display("out=%b a=%b b=%b, time =%0d",out,a,b,$time);
$display("fail");
end
else
begin
$display("out=%b a=%b b=%b,, time =%0d",out,a,b,$time);
$display("OK");
end
end
#30 $finish;
end
initial
forever
#2 clk=~clk;
//initial
//$monitor("out=%b a=%b b=%b",out,a,b);
endmodule

output:

out=xxxxxxxxxxxxxxxx a=00000000 b=00000000,, time =6
OK
out=xxxxxxxxxxxxxxxx a=00000001 b=00000001,, time =10
OK
out=0000000000000000 a=00000010 b=00000010, time =14
fail
out=0000000000000001 a=00000011 b=00000011, time =18
fail
out=0000000000000100 a=00000100 b=00000100, time =22
fail
out=0000000000001001 a=00000101 b=00000101, time =26
fail
Done

Note: the design is working incorretly the output is 2 cycles delayed by the corresponding input hence causing the fails to occur. fix the design for flaws


Related Solutions

module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2;...
module traffic(clk, reset, P1, P2, P3, P4, PL); input clk; input reset; output[4:0] P1; output[4:0] P2; output[4:0] P3; // four roads output [4:0] P4; output[3:0] PL; //Pl is pedestrian reg [4:0] P1; reg [4:0] P2; reg [4:0] P3; reg [4:0] P4; reg [3:0] PL; reg [4:0] sig; always @(posedge clk or negedge reset) begin    if(reset == 1'b0)begin        P1 <= 5'b00100;        P2 <= 5'b00100;        P3 <= 5'b00100;        P4 <= 5'b00100;       ...
can i ask FSM verilog? ---------------------- module FSM(clk, rst, choice, out); input clk, rst, choice; output...
can i ask FSM verilog? ---------------------- module FSM(clk, rst, choice, out); input clk, rst, choice; output reg [1:0] out; reg [1:0] state, nextstate; parameter [1:0] S0 = 2’b00, S1 = 2’b01, S2 = 2’b10, S3 = 2’b11; always@(posedge clk) begin if (rst == 1’b0) begin state <= S0; end else end state <= nextstate; always@(state, rst, choice) begin case (state) S0 : begin out = 2’b00; if (rst == 1’b1) nextstate <= S1; end S1 : begin out = 2’b01;...
What is the output of the following code: x = 0 a = 1 b =...
What is the output of the following code: x = 0 a = 1 b = -3 if a > 0:    if b < 0:       x = x + 5    elif a > 5:       x = x + 4    else:       x = x + 3 else:     x = x + 2 print(x) 4 2 5 3 Consider the following code segment:    sum = 0.0    while True:       number = input(“Enter a...
Can someone create a Test bench for this 4 Bit USR code so that it can...
Can someone create a Test bench for this 4 Bit USR code so that it can shift left, shift right and Load. This is in VHDL. Please type out the code. library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity Uni_reg is port( LR,SP,clk,clear,shL,shR: in std_logic; -- shL = shift left shR= shift right Da,Db,Dc : in std_logic; --inputs for load Qa,Qb,Qc : out std_logic); --out puts from the flipflops end Uni_reg; architecture Structural of Uni_reg is signal lr1,lr2,sp1,sp2,R1,R2,R3 : std_logic; signal L1,L2,L3,LOAD1,LOAD2,LOAD3:std_logic; signal...
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001...
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001 input reset; //g for pedes = 000 red = 111 input ind; output[2:0] P1; output[2:0] P2; // two roads output[1:0] PL1; //Pl is pedestrian output[1:0] PL2; reg [2:0] P1; reg [2:0] P2; reg [1:0] PL1; reg [1:0] PL2; reg [2:0] sig; always @(posedge clk, posedge reset) if(reset) begin P1 <= 3'b100; P2 <= 3'b001; PL1 <= 3'b111; PL2 <= 3'b000; end else begin //...
Analyze the following Verilog code and write down its output as pictured in the code. module...
Analyze the following Verilog code and write down its output as pictured in the code. module blocking; reg [0:7] A, B; initial begin: init1 A = last decimal digit of your ID; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Output 1: A= %b B= %b", A, B ); A = last decimal digit of your ID; #1 A <= A + 1; B <= A + 1; #1 $display ("Output 2: A=...
Write the Verilog code and test bench for the following circuits: - Mealy State machine design...
Write the Verilog code and test bench for the following circuits: - Mealy State machine design for a Serial Adder Circuit - Moore State Machine design for a Serial Adder Circuit
The goal in this experiment is to implement a 0-12 counter with a test bench that...
The goal in this experiment is to implement a 0-12 counter with a test bench that displays the output of each of the flip-flops in the counter. A behavioral code should be written for this experiment. Set the time format to 1 nanosecond with a precision of 100 picosecond.
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT