Collaborative - Fixes and Testbenches for Basic Modules so far

This commit is contained in:
goochey
2019-02-16 16:29:12 -05:00
parent 84e3725fdb
commit faf9f883dd
166 changed files with 4884 additions and 170 deletions

View File

@@ -35,8 +35,7 @@ module ALU(
and_9bit and0(
.A(operand0),
.B(operand1),
.Cin(1'b0),
.Sum(result_E));
.C(result_E));
// F (101) - Shift Logical Left
shift_logical_left sll(
.A(operand0),

View File

@@ -12,6 +12,44 @@ module add_1bit(
endmodule
//testbench
//module add1bit_tb();
//reg v;
//reg w;
//reg x;
//wire y;
//wire z;
//add_1bit add0(
// .A(v),
// .B(w),
// .Cin(x),
// .S(y),
// .Cout(z));
// initial begin
// v = 0;
// w = 0;
// x = 0;
// #5
// v = 0;
// w = 1;
// x = 0;
// #5
// v = 0;
// w = 0;
// x = 1;
// #5
// v = 1;
// w = 1;
// x = 0;
// #5
// v = 1;
// w = 1;
// x = 1;
// end
//endmodule
module add_9bit(
input wire [8:0] A,
input wire [8:0] B,
@@ -93,6 +131,45 @@ module add_9bit(
endmodule
//testbench
//module add9bit_tb();
//reg [8:0] a;
//reg [8:0] b;
//reg cin;
//wire [8:0] s;
//wire cout;
//add_9bit add0(
// .A(a),
// .B(b),
// .Cin(cin),
// .Sum(s),
// .Cout(cout));
// initial begin
// a = 9'b000000000;
// b = 9'b000000000;
// cin = 0;
// #5
// a = 9'b000000001;
// b = 9'b000000000;
// cin = 0;
// #5
// a = 9'b000000000;
// b = 9'b000000001;
// cin = 1;
// #5
// a = 9'b000000001;
// b = 9'b000000001;
// cin = 0;
// #5
// a = 9'b000001000;
// b = 9'b000000001;
// cin = 1;
// end
//endmodule
module and_1bit(
input wire A,
input wire B,
@@ -102,6 +179,34 @@ module and_1bit(
endmodule
//testbench
//module and1bit_tb();
//reg a;
//reg b;
//wire c;
//and_1bit and0(
//.A(a),
//.B(b),
//.C(c));
// initial begin
// a = 0;
// b = 0;
// #5
// a = 0;
// b = 1;
// #5
// a = 1;
// b = 0;
// #5
// a = 1;
// b = 1;
// #5 $finish;
// end
//endmodule
module and_9bit(
input wire [8:0] A,
input wire [8:0] B,
@@ -154,6 +259,40 @@ module and_9bit(
endmodule
//testbench
//module and9bit_tb();
//reg [8:0] a;
//reg [8:0] b;
//wire [8:0] c;
//and_9bit and0(
//.A(a),
//.B(b),
//.C(c));
// initial begin
// a = 9'b000000000;
// b = 9'b000000000;
// #5
// a = 9'b000000000;
// b = 9'b000000001;
// #5
// a = 9'b000000001;
// b = 9'b000000000;
// #5
// a = 9'b000000001;
// b = 9'b000000001;
// #5
// a = 9'b000100001;
// b = 9'b000000001;
// #5
// a = 9'b000100001;
// b = 9'b000100001;
// #5 $finish;
// end
//endmodule
module gen_clock();
reg clk;
initial begin
@@ -164,6 +303,12 @@ module gen_clock();
end
endmodule
// testbench
//module gen_clock_tb();
//reg clk;
// gen
module mux_2_1(input wire switch,
input wire [8:0] A,B,
output reg [8:0] out);
@@ -178,6 +323,48 @@ module mux_2_1(input wire switch,
endmodule
//testbench
//module mux_2_1_tb();
//reg s;
//reg [8:0] a;
//reg [8:0] b;
//wire [8:0] c;
//mux_2_1 mux0(
//.switch(s),
//.A(a),
//.B(b),
//.out(c));
// initial begin
// s = 0;
// a = 9'b000000101;
// b = 9'b000000000;
// #5
// s = 1;
// a = 9'b000000001;
// b = 9'b000100001;
// #5
// s = 0;
// a = 9'b000000000;
// b = 9'b000000001;
// #5
// s = 1;
// a = 9'b000000001;
// b = 9'b000000001;
// #5
// s = 0;
// a = 9'b000010001;
// b = 9'b000000001;
// #5
// s = 1;
// a = 9'b000010001;
// b = 9'b000010111;
// #5 $finish;
// end
//endmodule
module mux_4_1(input wire [1:0] switch,
input wire [8:0] A,B,C,D,
output reg [8:0] out);
@@ -194,6 +381,52 @@ module mux_4_1(input wire [1:0] switch,
endmodule
//testbench
//module mux_4_1_tb();
//reg [1:0] s;
//reg [8:0] a;
//reg [8:0] b;
//reg [8:0] c;
//reg [8:0] d;
//wire [8:0] e;
//mux_4_1 mux1(
//.switch(s),
//.A(a),
//.B(b),
//.C(c),
//.D(d),
//.out(e));
// initial begin
// s = 2'b00;
// a = 9'b000000101;
// b = 9'b000111100;
// c = 9'b001001001;
// d = 9'b100000000;
// #5
// s = 2'b01;
// a = 9'b000000101;
// b = 9'b000111100;
// c = 9'b001001001;
// d = 9'b100000000;
// #5
// s = 2'b10;
// a = 9'b000000101;
// b = 9'b000111100;
// c = 9'b001001001;
// d = 9'b100000000;
// #5
// s = 2'b11;
// a = 9'b000000101;
// b = 9'b000111100;
// c = 9'b001001001;
// d = 9'b100000000;
// #5 $finish;
// end
//endmodule
module mux_8_1(
input wire [2:0] switch,
input wire [8:0] A,B,C,D,E,F,G,H,
@@ -215,44 +448,127 @@ module mux_8_1(
endmodule
module mux_16_1(
input wire [3:0] switch,
input wire [8:0] A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,
output reg [8:0] out);
always @(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,switch) begin
case (switch)
4'b0000 : out = A;
4'b0001 : out = B;
4'b0010 : out = C;
4'b0011 : out = D;
4'b0100 : out = E;
4'b0101 : out = F;
4'b0110 : out = G;
4'b0111 : out = H;
4'b1000 : out = I;
4'b1001 : out = J;
4'b1010 : out = K;
4'b1011 : out = L;
4'b1100 : out = M;
4'b1101 : out = N;
4'b1110 : out = O;
4'b1111 : out = P;
default : out = 9'bxxxxxxxxx;
endcase
end
//testbench
//module mux_8_1_tb();
//reg [2:0] s;
//reg [8:0] a;
//reg [8:0] b;
//reg [8:0] c;
//reg [8:0] d;
//reg [8:0] e;
//reg [8:0] f;
//reg [8:0] g;
//reg [8:0] h;
//wire [8:0] out;
endmodule
//mux_8_1 mux1(
//.switch(s),
//.A(a),
//.B(b),
//.C(c),
//.D(d),
//.E(e),
//.F(f),
//.G(g),
//.H(h),
//.out(out));
// initial begin
// s = 3'b000;
// a = 9'b000000101;
// b = 9'b000111100;
// c = 9'b001001001;
// d = 9'b100110000;
// e = 9'b010000101;
// f = 9'b010111100;
// g = 9'b011001001;
// h = 9'b111000000;
// #5
// s = 3'b001;
// #5
// s = 3'b010;
// #5
// s = 3'b011;
// #5
// s = 3'b100;
// #5
// s = 3'b101;
// #5
// s = 3'b110;
// #5
// s = 3'b111;
// #5 $finish;
// end
//endmodule
//module mux_16_1(
// input wire [3:0] switch,
// input wire [8:0] A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,
// output reg [8:0] out);
// always @(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,switch) begin
// case (switch)
// 4'b0000 : out = A;
// 4'b0001 : out = B;
// 4'b0010 : out = C;
// 4'b0011 : out = D;
// 4'b0100 : out = E;
// 4'b0101 : out = F;
// 4'b0110 : out = G;
// 4'b0111 : out = H;
// 4'b1000 : out = I;
// 4'b1001 : out = J;
// 4'b1010 : out = K;
// 4'b1011 : out = L;
// 4'b1100 : out = M;
// 4'b1101 : out = N;
// 4'b1110 : out = O;
// 4'b1111 : out = P;
// default : out = 9'bxxxxxxxxx;
// endcase
// end
//endmodule
module nor_1bit(
input wire A,
input wire B,
output wire C);
assign C = A |~ B;
//assign C = A |~ B;
assign C = ~(A | B);
endmodule
//testbench
//module nor_1bit_tb();
//reg a;
//reg b;
//wire c;
//nor_1bit nor0(
//.A(a),
//.B(b),
//.C(c));
// initial begin
// a = 0;
// b = 0;
// #5
// a = 0;
// b = 1;
// #5
// a = 1;
// b = 0;
// #5
// a = 1;
// b = 1;
// #5 $finish;
// end
//endmodule
module nor_9bit(
input wire [8:0] A,
input wire [8:0] B,
@@ -305,6 +621,41 @@ module nor_9bit(
endmodule
//testbench
//module nor_9bit_tb();
//reg [8:0] a;
//reg [8:0] b;
//wire [8:0] c;
//nor_9bit nor0(
//.A(a),
//.B(b),
//.C(c));
// initial begin
// a = 9'b000000000;
// b = 9'b000000000;
// #5
// a = 9'b000000000;
// b = 9'b000000001;
// #5
// a = 9'b000000001;
// b = 9'b000000000;
// #5
// a = 9'b000000001;
// b = 9'b000000001;
// #5
// a = 9'b000100001;
// b = 9'b000000001;
// #5
// a = 9'b000100001;
// b = 9'b000100001;
// #5 $finish;
// end
//endmodule
module not_1bit(
input wire A,
output wire B);
@@ -313,6 +664,24 @@ module not_1bit(
endmodule
//testbench
//module not_1bit_tb();
//reg a;
//wire b;
//not_1bit not0(
//.A(a),
//.B(b));
// initial begin
// a = 0;
// #5
// a = 1;
// #5 $finish;
// end
//endmodule
module not_9bit(
input wire [8:0] A,
output wire [8:0] B);
@@ -355,6 +724,35 @@ module not_9bit(
endmodule
//testbench
//module not_9bit_tb();
//reg [8:0] a;
//wire [8:0] b;
// not_9bit not0(
// .A(a),
// .B(b));
// initial begin
// a = 9'b000000000;
// #5
// a = 9'b000000001;
// #5
// a = 9'b000111000;
// #5
// a = 9'b010101010;
// #5
// a = 9'b101010101;
// #5
// a = 9'b111111111;
// #5
// a = 9'b100000001;
// #5 $finish;
// end
//endmodule
module or_1bit(
input wire A,
input wire B,
@@ -364,6 +762,35 @@ module or_1bit(
endmodule
//testbench
//module or_1bit_tb();
//reg a;
//reg b;
//wire c;
// or_1bit or0(
// .A(a),
// .B(b),
// .C(c));
// initial begin
// a = 0;
// b = 0;
// #5
// a = 0;
// b = 1;
// #5
// a = 1;
// b = 0;
// #5
// a = 1;
// b = 1;
// #5 $finish;
// end
//endmodule
module or_9bit(
input wire [8:0] A,
input wire [8:0] B,
@@ -416,6 +843,50 @@ module or_9bit(
endmodule
//testbench
//module or_9bit_tb();
//reg [8:0] a;
//reg [8:0] b;
//wire [8:0] c;
// or_9bit tb0(
// .A(a),
// .B(b),
// .C(c));
// initial begin
// a = 9'b000000000;
// b = 9'b000000000;
// #5
// a = 9'b111111111;
// b = 9'b111111111;
// #5
// a = 9'b111111111;
// b = 9'b000000000;
// #5
// a = 9'b000000000;
// b = 9'b111111111;
// #5
// a = 9'b000000000;
// b = 9'b111111111;
// #5
// a = 9'b010101010;
// b = 9'b111111111;
// #5
// a = 9'b010101010;
// b = 9'b101010101;
// #5
// a = 9'b000011111;
// b = 9'b111111111;
// #5
// a = 9'b000000000;
// b = 9'b000010000;
// #5 $finish;
// end
//endmodule
module register(input wire clk, reset,
input wire [1:0] En,
input wire [8:0] Din,
@@ -429,54 +900,143 @@ module register(input wire clk, reset,
Dout = Din;
end
else begin
Dout = "ZZZZZZZZZ";
Dout = 9'bZZZZZZZZZ;
end
end
endmodule
//Mux follows intuitive switching
module mux(input wire [1:0] switch,
input wire [8:0] A,B,C,D,
output reg [8:0] out);
always @(A,B,C,D,switch) begin
if (switch == 2'b00) begin
out = A;
end
else if (switch == 2'b01) begin
out = B;
end
else if (switch == 2'b10) begin
out = C;
end
else if (switch == 2'b11) begin
out = D;
end
else begin
out = "ZZZZZZZZZ";
end
end
endmodule
//testbench
//module register_tb();
//reg clk,reset;
//reg [1:0] En;
//reg [8:0] Din;
//wire [8:0] Dout;
// register tb0(
// .clk(clk),
// .reset(reset),
// .En(En),
// .Din(Din),
// .Dout(Dout));
// initial begin
// clk = 0;
// reset = 0;
// En = 2'b00;
// Din = 9'b000000000;
// #5
// clk = 1;
// #5
// clk = 0;
// reset = 0;
// En = 2'b00;
// Din = 9'b010101010;
// #5
// clk = 1;
// #5
// clk = 0;
// reset = 1;
// En = 2'b00;
// Din = 9'b010101010;
// #5
// clk = 1;
// #5
// clk = 0;
// reset = 0;
// En = 2'b01;
// Din = 9'b101010101;
// #5
// clk = 1;
// #5
// clk = 0;
// reset = 0;
// En = 2'b00;
// Din = 9'b000011111;
// #5
// clk = 1;
// #5
// clk = 0;
// #5 $finish;
// end
//endmodule
module shift_logical_left(
input wire [8:0] A,
output wire [8:0] B);
assign B = {A[7:0],A[8]};
assign B = {A[7:0],1'b0};
endmodule
//testbench
//module shift_logical_left_tb();
//reg [8:0] a;
//wire [8:0] b;
// shift_logical_left tb0(
// .A(a),
// .B(b));
// initial begin
// a = 9'b000000000;
// #5
// a = 9'b000000001;
// #5
// a = 9'b000111000;
// #5
// a = 9'b010101010;
// #5
// a = 9'b101010101;
// #5
// a = 9'b111111111;
// #5
// a = 9'b100000001;
// #5 $finish;
// end
//endmodule
module shift_logical_right(
input wire [8:0] A,
output wire [8:0] B);
assign B = {A[0],A[8:1]};
assign B = {1'b0,A[8:1]};
endmodule
//testbench
//module shift_logical_right_tb();
//reg [8:0] a;
//wire [8:0] b;
// shift_logical_right tb0(
// .A(a),
// .B(b));
// initial begin
// a = 9'b000000000;
// #5
// a = 9'b000000001;
// #5
// a = 9'b000111000;
// #5
// a = 9'b010101010;
// #5
// a = 9'b101010101;
// #5
// a = 9'b111111111;
// #5
// a = 9'b100000001;
// #5 $finish;
// end
//endmodule
// No D instance, fix
module sub_9bit(
input wire [8:0] A,
input wire [8:0] B,
@@ -496,6 +1056,50 @@ module sub_9bit(
endmodule
//testbench
//module sub_9bit_tb();
//reg [8:0] a;
//reg [8:0] b;
//wire [8:0] c;
// sub_9bit tb0(
// .A(a),
// .B(b),
// .C(c));
// initial begin
// a = 9'b000000000;
// b = 9'b000000000;
// #5
// a = 9'b111111111;
// b = 9'b111111111;
// #5
// a = 9'b111111111;
// b = 9'b000000000;
// #5
// a = 9'b000000000;
// b = 9'b111111111;
// #5
// a = 9'b000000000;
// b = 9'b111111111;
// #5
// a = 9'b010101010;
// b = 9'b111111111;
// #5
// a = 9'b010101010;
// b = 9'b101010101;
// #5
// a = 9'b000011111;
// b = 9'b111111111;
// #5
// a = 9'b000000000;
// b = 9'b000010000;
// #5 $finish;
// end
//endmodule
module twos_compliment_9bit(
input wire [8:0] A,
output wire [8:0] B);
@@ -512,4 +1116,33 @@ module twos_compliment_9bit(
.Cin(1'b1),
.Sum(B));
endmodule
endmodule
//testbench
//module twos_compliment_tb();
//reg [8:0] a;
//wire [8:0] b;
// twos_compliment_9bit tb0(
// .A(a),
// .B(b));
// initial begin
// a = 9'b000000000;
// #5
// a = 9'b000000001;
// #5
// a = 9'b000111000;
// #5
// a = 9'b010101010;
// #5
// a = 9'b101010101;
// #5
// a = 9'b111111111;
// #5
// a = 9'b100000001;
// #5 $finish;
// end
//endmodule

View File

@@ -1,7 +1,6 @@
`timescale 1ns / 1ps
module FetchUnit(input wire clk, reset, op_idx,
input wire [1:0] write_index,
input wire [8:0] AddrIn,
output wire [8:0] AddrOut);
@@ -11,7 +10,7 @@ module FetchUnit(input wire clk, reset, op_idx,
register PC(
.clk(clk),
.reset(reset),
.En({write_index[0], write_index[1]}),
.En(2'b00),
.Din(result_m),
.Dout(progC_out));
//Adds 1 to the program counter
@@ -19,11 +18,11 @@ module FetchUnit(input wire clk, reset, op_idx,
.A(progC_out),
.B(1'b1),
.Cin(1'b0),
.Sum(result_a));
.Sum(AddrOut));
mux_2_1 PCmux(
.A(AddrIn),
.B(result_a),
.B(AddrOut),
.out(result_m),
.switch(op_idx));