Untitled
raw download clone
VERILOG
views 30
,
size 2002 b
`timescale 1ns/1ps
`define CYC 4

module tb();

    reg [32 - 1:0] A, B;
    reg [2:0] sel;
    wire[32 - 1:0] Y;
    wire Negative, Zero;
    reg clk = 1'b0;

    ALU t(.A(A), .B(B), .Y(Y), .sel(sel), .Negative(Negative), .Zero(Zero));

    initial begin
        $fsdbDumpfile("lab2_2.fsdb");
        $fsdbDumpvars;
    end

    always #(`CYC / 2) clk = ~clk;

    initial begin
        {A, B} = {32'b0, 32'b00101010101010101010101010101010};
        sel = 3'b111;

        repeat(2 ** 3) begin
            @ (posedge clk) #1;
                A = A + 32'b1;
                B = B - 32'b1;
                sel = sel + 3'b001;
            @ (negedge clk) #1;
                if (    (sel === 3'b000 && Y === 32'b00000000000000000000000000000000 && Negative === 1'b0 && Zero === 1'b1) ||
                        (sel === 3'b001 && Y === 32'b00000000000000000000000000000000 && Negative === 1'b0 && Zero === 1'b1) ||
                        (sel === 3'b010 && Y === 32'b00101010101010101010101010100111 && Negative === 1'b0 && Zero === 1'b0) ||
                        (sel === 3'b011 && Y === 32'b00101010101010101010101010100010 && Negative === 1'b0 && Zero === 1'b0) ||
                        (sel === 3'b100 && Y === 32'b11111111111111111111111111111010 && Negative === 1'b1 && Zero === 1'b0) ||
                        (sel === 3'b101 && Y === 32'b11010101010101010101010101100010 && Negative === 1'b1 && Zero === 1'b0) ||
                        (sel === 3'b110 && Y === 32'b00101010101010101010101010101010 && Negative === 1'b0 && Zero === 1'b0) ||
                        (sel === 3'b111 && Y === 32'b00000000000000000000000000010000 && Negative === 1'b0 && Zero === 1'b0)   ) begin
                    $display("correct\n");
                end else begin
                    $display("error, A = %b, B = %b, sel = %b, Y = %b, N = %b, Z = %b\n", A, B, sel, Y, Negative, Zero);
                end
        end
        #1 $finish;
    end

endmodule
close fullscreen
Login or Register to edit or fork this paste. It's free.