// // Title : 4 bit alu test fixture // Design : Homework 5 // Author : Steven Balensiefer, Carl Ebeling // Company : CSE 370 // //------------------------------------------------------------------------------------------------- // // File : alu_4bit_tf.v // // Description : This test fixture tests a 4-bit ALU made from 4 ALU bit-slices; //------------------------------------------------------------------------------------------------- `timescale 1ns / 1ns module alu_4bit_tf (A, B, Sel, Cin, F, Cout); output [3:0] A, B; output [2:0] Sel; // Data input, control to ALU output Cin; input [3:0] F; // Results from adder input Cout; reg [3:0] A, B; reg [2:0] Sel; // Data input to adder reg [3:0] Val; reg VCo; reg Cin; integer errors; integer count; integer funct; integer i, good; initial begin errors = 0; // Perform exhaustive test: for (funct = 1; funct < 7; funct = funct + 1) begin Sel = funct; Cin = (funct == 1 || funct == 2)? 1'b1 : 1'b0; for (count = 0; count < 256; count = count + 1) begin {A,B} = count; #20 good = 1; case(funct) 0 : {VCo,Val} = 5'b00000; 1 : {VCo,Val} = B + (~A) + 1; 2 : {VCo,Val} = A + (~B) + 1; 3 : {VCo,Val} = A + B; 4 : {VCo,Val} = {1'b0,A[3:0]^B[3:0]}; 5 : {VCo,Val} = {1'b0,A[3:0]|B[3:0]}; 6 : {VCo,Val} = {1'b0,A[3:0]&B[3:0]}; 7 : {VCo,Val} = 5'b01111; default $display( "Error in funct" ); endcase for (i = 0; i < 4; i = i + 1) begin if (Val[i] !== F[i]) good = 0; end if (!good) begin $display("***Error*** A:%b, B:%b, Cin%b, Sel:%b, F:%b, Cout:%b\nShould Be F:%b, Cout:%b", A, B, Cin, Sel, F, Cout,Val,VCo); errors = errors + 1; $stop; end end end if (errors == 0) $display("Test passed - No errors!!"); else $display("**** %d Errors****", errors); end endmodule