alu_tb.v 1.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
`default_nettype none

module top;

    reg [2:0] operation;
    reg [31:0] left, right;
    wire [31:0] result;

    ALU dut(
        .operation(operation),
        .left(left),
        .right(right),
        .result(result)
    );

    initial begin
        $monitor($time, " %h %d %h = %h", left, operation, right, result);
        operation = 3'd0;
        left = 32'h0;
        right = 32'h0;
        #10;
        left = 32'h80000000;
        right = 32'd16;
        #10;
        operation = 3'd1;
        #10;
        left = 32'h7fff0003;
        right = 32'd1;
        #10;
        right = 32'd0;
        #10;
        right = 32'd8;
        #10;
        operation = 3'd2;
        left = 32'hffffffff;
        right = 32'h10;
        #10;
        left = 32'h1;
        right = 32'h10;
        #10;
        left = 32'h10;
        right = 32'hffffffff;
        #10;
        operation = 3'd3;
        left = 32'h80000000;
        right = 32'h7fffffff;
        #10;
        left = 32'hff;
        right = 32'h80000000;
        #10;
        operation = 3'd2;
        left = 32'd10;
        right = 32'd20;
        #10;
        left = 32'd20;
        right = 32'd10;
        #10;
        left = 32'hffffffff; // -1
        right = 32'hfffff000;
        #10;
        left = 32'hfffff000;
        right = 32'hffffffff;
        #10;
        left = 32'hfffff000;
        right = 32'h10;
        #10;
        left = 32'h10;
        right = 32'hfffff000;
        #10;
        // operation = 3'd1;
        // // for(left = 32'b0; left < 32'hffffffff; left = left + 32'b1)
        // //     for(right = 32'b0; right <= 32'd31; right = right + 32'b1)
        // //         #10 if(result != dut.result2) $error("Bad match: %h %h", result, dut.result2);
        // // #10;
        // left = 32'hffffffff;
        // for(right = 32'b0; right <= 32'd31; right = right + 32'd1)
        //     #10 if(result != dut.result2) $error("Bad match: %h %h", result, dut.result2);
        // #10;
        $finish;
    end

endmodule