Please help to complete the code and write the testbench to design the following adder.
1.In this section, you add pipeline stage. 8 bits are used at
every pipeline stage.Use the following template to complete your
Verilog coding.
// Addition of two 16 bit, 2's complement nos., n1 and n2. 8 bits
addition at a time. Result is 17 bits.
module adder_b (clk, n1, n2, sum) ;
input clk ;
input [15:0] n1 ;
input [15:0] n2 ;
output [16:0] sum ;
reg [16:0] sum ;
wire [8:0] sum_LSB ;
reg [8:0] sum_LSB_1 ;
reg [15:8] n1_reg1 ;
reg [15:8] n2_reg1 ;
wire [16:8] sum_MSB ;
wire [16:0] sum_next ;
assign sum_LSB = ____ ; // Add least 8 significant bits. sum_LSB
[8] is the carry.
always @ (posedge clk) // Pipeline 1, clk (1), register LSB to
continue addition of MSB.
begin
sum_LSB_1 <= _________; // Preserve LSB sum
n1_reg1 <= __________; // Preserve MSBs of n1
n2_reg1 <= __________;// Preserve MSBs of n2
end
// Extend sign & add msbs with carry.
assign sum_MSB = ____________________; // Add MSBs with
carry.
assign sum_next = _____________________;
always @ (posedge clk) // Pipeline 2, clk (2), register
result.
begin
sum <= ___________;
end
endmodule
// Addition of two 16 bit, 2's complement nos., n1 and n2. 8 bits addition at a time. Result is 17 bits.
module adder_b (clk, n1, n2, sum) ;
//input port declarations
input clk ;
input [15:0] n1 ;
input [15:0] n2 ;
//output port declarations
output [16:0] sum ;
reg [16:0] sum ;
//internal signal declarations
wire [8:0] sum_LSB ;
reg [8:0] sum_LSB_1 ;
reg [15:8] n1_reg1 ;
reg [15:8] n2_reg1 ;
wire [16:8] sum_MSB ;
wire [16:0] sum_next ;
assign sum_LSB = n1[7:0] + n2[7:0] ; // Add least 8 significant bits. sum_LSB [8] is the carry.
always @ (posedge clk) // Pipeline 1, clk (1), register LSB to continue addition of MSB.
begin
sum_LSB_1 <= sum_LSB ; // Preserve LSB sum
n1_reg1 <= n1[15:8]; // Preserve MSBs of n1
n2_reg1 <= n2[15:8];// Preserve MSBs of n2
end
// Extend sign & add msbs with carry.
assign sum_MSB = n1_reg1 + n2_reg1 + sum_LSB_1[8] ; // Add MSBs with carry.
assign sum_next = {sum_MSB , sum_LSB_1[7:0]} ;
always @ (posedge clk) // Pipeline 2, clk (2), register result.
begin
sum <= sum_next;
end
endmodule
// verilog testbench code for given adder module
module test_adder;
//inputs
reg clk;
reg [15:0] n1;
reg [15:0] n2;
wire [16:0] sum;
//instantiate DUT
adder_b DUT (.clk(clk),.n1(n1),.n2(n2),.sum(sum));
//clock generation
initial begin
clk = 0;
forever #5 clk = ~clk;
end
//2's complement binary inputs
initial begin
$dumpfile ("");
$dumpvars;
n1 = 16'd11; n2 = 16'd13 ;#20;
n1 = 16'd01; n2 = 16'd67 ;#20;
n1 = 16'd9; n2 = 16'd56 ;#20;
n1 = 16'd53; n2 = 16'd56 ;#20;
n1 = 16'd67; n2 = 16'd43 ;#20;
n1 = 16'd87; n2 = 16'd13 ;#20;
$finish;
end
endmodule
// Simulation waveforms
Please help to complete the code and write the testbench to design the following adder. 1.In...
Write a testbench for use in Quartus' ModelSim Altera in verilog for the following code of a 4x16 register: module regFile4x16 (input clk, input write, input [2:0] wrAddr, input [15:0] wrData, input [2:0] rdAddrA, output [15:0] rdDataA, input [2:0] rdAddrB, output [15:0] rdDataB); reg [15:0] reg0, reg1, reg2, reg3; assign rdDataA = rdAddrA == 0 ? reg0 : rdAddrA == 1 ? reg1 : rdAddrA == 2 ? reg2 : rdAddrA == 3...
Write a testbench for LFShift shift register example module 1f3r input clk, input reset, output a ); reg (5:0] shift; wire xor_sum; assign xor_sum = shift[1] ^ shift[4]; // feedback taps always @ (posedge clk) if (reset) shift <= 6'b111111; // initialize LFSR else shift <= { xor_sum, shift [5:1] }; // shift right assign a = shift[0]; // output of LFSR endmodule
a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes are doing by adding comments in the code. Then write down the simulation results of res1, res2, res3, and res4, respectively. Source code module vector_defn (num1, res1, res2, res3, res4); input [7:0] num1; output res1; output [3:0] res2; output [0:7] res3; output [15:0] res4; assign res1=num1[2]; assign res2=num1[7:4]; assign res3=num1; assign res4={2{num1}}; endmodule testbench: `timescale 1ns / 1ps module vector_defn_tb; reg [7:0] in1; wire...
(15 pts) 1. Draw a logic diagram for the Verilog code. module Seq_Ckt ( CLK, PR, sel, Q); input CLK, PR, sel; output reg [2:0] Q; reg [2:0] y; assign Q = y; always @ (posedge PR, posedge CLK) begin if (PR== 1) then y <= 3'b111; else if (sel) begin y[2] <= y[1] ^ y[0]; y[1] <= y[2]; y[1]; end else y[2] <= y[2] ; y[1] <= y[1]; y[0]; y[O] <= y[0] <= end endmodule
Please explain what he verilog code does: module lab7_2_3( input clk, input Enable, input Clear, input Load, output [3:0] Q, reg [3:0] count, wire cnt_done ); assign cnt_done = ~| count; assign Q = count; always @(posedge clk) if (Clear) count <= 0; else if (Enable) if (Load | cnt_done) count <= 4'b1010; // decimal 10 else count <= count - 1; Endmodule
I need help writing a test bench for the following Verilog code module CU(IE, WE, WA, RAE, RAA, RBE, RBA, ALU, SH, OE, start, clk, reset, Ng5); //nG5 denotes (N>5); input start, clk, reset; output IE, WE, RAE, RBE, OE; output [1:0] WA, RAA, RBA, SH; output [2:0] ALU; input wire Ng5; reg [1:0] state; reg [1:0] nextstate; parameter S0 = 3'b000; parameter S1 = 3'b001;...
– Write and test a constrained random stimulus testcase for the testbench. Use ModelSim or a similar simulator to test the transactor. Provide the code and evidence of its function. // ---------------------------------------------------------------------------- // File name: alu.v // Designed by: Jim Moran // ---------------------------------------------------------------------------- // // This module is the Arithmetic Logic Unit // // ---------------------------------------------------------------------------- `timescale 1ns/1ps //----------------------------------------------------------------------------- // Module Declaration //----------------------------------------------------------------------------- module alu ( // Global Signals Clk_In, // Rising Edge Clock Input Rst_l_In, // Active Low Reset Input ...
Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset, clk, TB, TA, output reg [1:0] LB, LA); reg [1:0] cstate, nstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter grn = 2'b00; parameter ylw = 2'b01; parameter rd = 2'b10; // state register always @ (posedge clk, posedge reset) begin if (reset) cstate <= S0; else cstate <= nstate; end // next state logic...
1&2 and please I need quickly. Q1 (35 pts): Design a combinational circuit that takes 8 bits of input and checks iif the inputs are symmetric or not and produces an output immediately. Example: 10011001 or 11000011 produce 1 and 11011010 or 11001100 produce 0.) (a) Write Verilog RTL for this circuit. (b) Same functionality but output appears next cycle. You can instantiate the design in part a. (c) Same functionality but output appeurs after two cycles. You can instantiate...
How do I create a testbench with the verilog code below? module ganada(Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4, CF, S); input Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4; output [6:0] CF, S; reg [6:0] CF, S; reg [1:0] SS, B, NS; initial begin NS=2'b00; SS=2'b00; end always@(posedge Clk) begin case(NS) 2'b00: CF=7'b1111001; 2'b01: CF=7'b0100100; 2'b10: CF=7'b0110000; 2'b11: CF=7'b0011001; endcase case(SUD) 2'b00: S=7'b1000000; 2'b01: S=7'b1111001; 2'b10: S=7'b0100100; default: S=7'b0000000; endcase if(U1==1 ||...