From 37db52dbd66db1fd43337082249c469eda39f776 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Thu, 1 Dec 2016 21:36:51 -0600 Subject: initial commit --- shifter_tb.v | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 shifter_tb.v (limited to 'shifter_tb.v') diff --git a/shifter_tb.v b/shifter_tb.v new file mode 100644 index 0000000..7d28915 --- /dev/null +++ b/shifter_tb.v @@ -0,0 +1,100 @@ +`timescale 1 ns / 100 ps + +module shifter_tb (); + reg [15:0] v; + reg [15:0] by; + reg dir; + reg [1:0] extend; + wire [15:0] result; + reg [15:0] expected_result; + + // xxxxxxxxxxxxxxxx1111101000001010xxxxxxxxxxxxxxxx + + initial begin + v = 16'hFA0A; + by = 16'h0; + dir = 1'b0; + extend = 2'h0; + expected_result = 16'hFA0A; + + #2 + by = 16'h1; + expected_result = 16'hF414; // 1111 0100 0001 0100 + + #2 + by = 16'h2; + expected_result = 16'hE828; // 1110 1000 0010 1000 + + #2 + dir = 1'b1; + expected_result = 16'h3E82; // 0011 1110 1000 0010 + + #2 + by = 16'h4; + expected_result = 16'h0FA0; // 0000 1111 1010 0000 + + #2 + dir = 1'b0; + expected_result = 16'hA0A0; // 1010 0000 1010 0000 + + #2 + extend = 2'h1; + expected_result = 16'hA0AF; // 1010 0000 1010 1111 + + #2 + dir = 1'b1; + expected_result = 16'hFFA0; // 1111 1111 1010 0000 + + #2 + extend = 2'h2; + dir = 1'b0; + expected_result = 16'hA0A0; // 1010 0000 1010 0000 + + #2 + dir = 1'b1; + expected_result = 16'hFFA0; // 1111 1111 1010 0000 + + #2 + extend = 2'h3; + expected_result = 16'hAFA0; // 1010 1111 1010 0000 + + #2 + dir = 1'b0; + expected_result = 16'hA0AF; // 1010 0000 1010 1111 + + #2 + v = 16'h0001; + extend = 2'h2; + dir = 1'b0; + by = 16'hE; + expected_result = 16'h7FFF; + + #2 + by = 16'h10; + expected_result = 16'hFFFF; + + #2 + dir = 1'b1; + expected_result = 16'h0000; + + #2 + dir = 1'b0; + by = 16'h1000; + expected_result = 16'hFFFF; + + #2 + dir = 1'b1; + expected_result = 16'h0000; + + #5 + $stop; + end + + shifter shifter_inst ( + .v(v), + .by(by), + .dir(dir), + .extend(extend), + .result(result) + ); +endmodule -- cgit v1.2.3