Skip to content

Commit 738e4b4

Browse files
committed
All HW
1 parent 3dfc9d8 commit 738e4b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3565
-0
lines changed

simulator1/alu1bit.sv

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// 1-bit ALU template
2+
module alu1bit (
3+
input logic a, // Input bit a
4+
input logic b, // Input bit b
5+
input logic cin, // Carry in
6+
input logic [1:0] op, // Operation
7+
output logic s, // Output S
8+
output logic cout // Carry out
9+
);
10+
11+
logic out_nor, out_nor_not, out_xor, out_s, a_ns;
12+
13+
OR2 #(.Tpdhl(3), .Tpdlh(2)) NOR_or (
14+
.Z(out_nor_or), .A(a), .B(b));
15+
16+
NOT #(.Tpdhl(7), .Tpdlh(10)) NOR_not (
17+
.Z(out_nor), .A(out_nor_or));
18+
19+
NOT #(.Tpdhl(7), .Tpdlh(10)) NOT_op0 (
20+
.Z(a_ns), .A(op[0]));
21+
22+
XOR2 #(.Tpdhl(2), .Tpdlh(1)) xor_inst (
23+
.Z(out_xor), .A(a), .B(b));
24+
25+
fas fas_alu(
26+
.a(a), .b(b), .cin(cin), .a_ns(a_ns), .s(out_s), .cout(cout));
27+
28+
mux4 mux_alu(
29+
.d0(out_nor), .d1(out_xor), .d2(out_s), .d3(out_s), .sel(op), .z(s)
30+
);
31+
32+
endmodule

simulator1/alu1bit_test.sv

Whitespace-only changes.

simulator1/alu64bit.sv

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// 64-bit ALU template
2+
module alu64bit (
3+
input logic [63:0] a, // Input bit a
4+
input logic [63:0] b, // Input bit b
5+
input logic cin, // Carry in
6+
input logic [1:0] op, // Operation
7+
output logic [63:0] s, // Output S
8+
output logic cout // Carry out
9+
);
10+
11+
logic [62:0] cout_from_fas;
12+
13+
alu1bit alu_inst1(
14+
.a(a[0]), .b(b[0]), .cin(cin), .op(op), .s(s[0]), .cout(cout_from_fas[0]));
15+
16+
genvar i;
17+
18+
generate
19+
for (i = 1; i < 63; i++)
20+
begin
21+
alu1bit alu_inst(
22+
.a(a[i]), .b(b[i]), .cin(cout_from_fas[i-1]), .op(op), .s(s[i]), .cout(cout_from_fas[i])
23+
);
24+
end
25+
endgenerate
26+
27+
alu1bit alu_inst64(
28+
.a(a[63]), .b(b[63]), .cin(cout_from_fas[62]), .op(op), .s(s[63]), .cout(cout)
29+
);
30+
31+
endmodule

simulator1/alu64bit_test.sv

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// 64-bit ALU test bench template
2+
module alu64bit_test;
3+
4+
//Gate inputs
5+
logic [63:0] alu_a;
6+
logic [63:0] alu_b;
7+
logic alu_cin;
8+
logic [1:0] alu_op;
9+
10+
//Gate outputs
11+
logic [63:0] alu_s;
12+
logic alu_cout;
13+
14+
alu64bit uut (.a(alu_a), .b(alu_b), .cin(alu_cin), .op(alu_op), .s(alu_s), .cout(alu_cout));
15+
16+
genvar i;
17+
18+
initial begin
19+
alu_op = 2'b10;
20+
alu_cin = 1'b0;
21+
alu_a = 64'b1111111111111111111111111111111111111111111111111111111111111111;
22+
alu_b = 64'b0000000000000000000000000000000000000000000000000000000000000000;
23+
#1700
24+
alu_b[0] = 1'b1;
25+
//more tests
26+
#3000
27+
alu_a = 64'b0111110111111011111111111011111101111111111111111011111101111101;
28+
alu_b = 64'b0100001100000011110011111110111100100000011000011111000111000011;
29+
#3000 //answer: 1100 0000 1111 1111 1100 1111 1010 1110 1010 0000 0110 0001 1011 0001 0100 0000
30+
alu_op = 2'b11;
31+
#1700 //answer: 0011 1010 1111 1000 0010 1111 1101 0000 0101 1111 1001 1101 1100 1101 1011 1010
32+
alu_op = 2'b00;
33+
#1700 //answer: 1000 0000 0000 0100 0000 0000 0000 0000 1000 0000 0000 0000 0000 0000 0000 0000
34+
alu_op = 2'b01;
35+
//answer: 0011 1110 1111 1000 0011 0000 0101 0000 0101 1111 1001 1110 0100 1110 1011 1110
36+
37+
end
38+
39+
endmodule

simulator1/dry_draft.docx

174 KB
Binary file not shown.

simulator1/fas.sv

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Full Adder/Subtractor template
2+
module fas (
3+
input logic a, // Input bit a
4+
input logic b, // Input bit b
5+
input logic cin, // Carry in
6+
input logic a_ns, // A_nS (add/not subtract) control
7+
output logic s, // Output S
8+
output logic cout // Carry out
9+
);
10+
11+
logic out1, out2, out3, out4, out5, out6, out8, out9, out10, out11;
12+
13+
XOR2 #(.Tpdhl(2), .Tpdlh(1)) g1 (
14+
.Z(out1), .A(a), .B(a_ns));
15+
16+
XOR2 #(.Tpdhl(2), .Tpdlh(1)) g6 (
17+
.Z(out6), .A(b), .B(cin));
18+
19+
XOR2 #(.Tpdhl(2), .Tpdlh(1)) g7 (
20+
.Z(s), .A(out6), .B(a));
21+
22+
NOT #(.Tpdhl(7), .Tpdlh(10)) g3 (
23+
.Z(out3), .A(b));
24+
25+
NOT #(.Tpdhl(7), .Tpdlh(10)) g4 (
26+
.Z(out4), .A(cin));
27+
28+
NOT #(.Tpdhl(7), .Tpdlh(10)) g5 (
29+
.Z(out5), .A(out2));
30+
31+
NOT #(.Tpdhl(7), .Tpdlh(10)) g10 (
32+
.Z(out10), .A(out8));
33+
34+
NOT #(.Tpdhl(7), .Tpdlh(10)) g11 (
35+
.Z(out11), .A(out9));
36+
37+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g2 (
38+
.Z(out2), .A(b), .B(cin));
39+
40+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g8 (
41+
.Z(out8), .A(out1), .B(out5));
42+
43+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g9 (
44+
.Z(out9), .A(out3), .B(out4));
45+
46+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g12 (
47+
.Z(cout), .A(out10), .B(out11));
48+
49+
endmodule

simulator1/fas_test.sv

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Full Adder/Subtractor test bench template
2+
module fas_test;
3+
4+
//Gate outputs
5+
logic fas_s;
6+
logic fas_cout;
7+
8+
// Gate inputs
9+
logic fas_a;
10+
logic fas_b;
11+
logic fas_cin;
12+
logic fas_a_ns;
13+
14+
fas uut (.a(fas_a), .b(fas_b), .cin(fas_cin), .a_ns(fas_a_ns), .s(fas_s), .cout(fas_cout));
15+
16+
17+
initial begin
18+
fas_a = 1'b0;
19+
fas_b = 1'b0;
20+
fas_cin = 1'b0;
21+
fas_a_ns = 1'b0;
22+
//testing
23+
#70
24+
fas_a = 1'b1;
25+
#70
26+
fas_a = 1'b0;
27+
//more tests
28+
#500
29+
fas_b = 1'b1;
30+
#500
31+
fas_cin = 1'b1;
32+
#500
33+
fas_a = 1'b1;
34+
#500
35+
fas_cin = 1'b0;
36+
#500
37+
fas_a_ns = 1'b1;
38+
#500
39+
fas_b = 1'b1;
40+
#500
41+
fas_cin = 1'b1;
42+
#500
43+
fas_b = 1'b0;
44+
#500
45+
fas_a = 1'b0;
46+
#500
47+
fas_cin = 1'b0;
48+
end
49+
50+
endmodule

simulator1/libcells/NOT.sv

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module NOT (
2+
input logic A,
3+
output logic Z
4+
);
5+
6+
parameter Tpdlh = 1;
7+
parameter Tpdhl = 1;
8+
9+
not #(Tpdlh, Tpdhl) not1 (Z, A);
10+
11+
endmodule

simulator1/libcells/OR2.sv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module OR2 (
2+
input logic A,
3+
input logic B,
4+
output logic Z
5+
);
6+
7+
parameter Tpdlh = 1;
8+
parameter Tpdhl = 1;
9+
10+
or #(Tpdlh, Tpdhl) or1 (Z, A, B);
11+
12+
endmodule

simulator1/libcells/XOR2.sv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module XOR2 (
2+
input logic A,
3+
input logic B,
4+
output logic Z
5+
);
6+
7+
parameter Tpdlh = 1;
8+
parameter Tpdhl = 1;
9+
10+
xor #(Tpdlh, Tpdhl) xor1 (Z, A, B);
11+
12+
endmodule

simulator1/libtest.sv

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/************************************************************************
2+
* Example testbench: instantiates 4 basic logic gates and applies *
3+
* stimulus to the gate inputs. *
4+
************************************************************************/
5+
module libtest;
6+
// Signal declarations
7+
// Gate output wires
8+
logic z1;
9+
logic z2;
10+
logic z3;
11+
12+
// Gate inputs
13+
logic a;
14+
logic b;
15+
16+
// The testbench: try different input combinations at different points
17+
// of time - change values every 10 time units.
18+
initial begin
19+
a = 1'b0;
20+
b = 1'b0;
21+
22+
#10;
23+
a = 1'b1;
24+
25+
#10;
26+
b = 1'b1;
27+
28+
#10
29+
$stop;
30+
end
31+
32+
// Gate instantiations
33+
// For this gate we override the default delays with: Tpdlh=5 and Tpdhl=7
34+
NOT #(
35+
.Tpdlh(5),
36+
.Tpdhl(7)
37+
) not_inst (
38+
.Z(z1),
39+
.A(a),
40+
);
41+
42+
// All the other gates stay with default (unit) delays, coded inside their
43+
// respective module definitions.
44+
OR2 or2_inst (
45+
.Z(z2),
46+
.A(a),
47+
.B(b)
48+
);
49+
XOR2 xor2_inst (
50+
.Z(z3),
51+
.A(a),
52+
.B(b)
53+
);
54+
55+
endmodule

simulator1/mux2.sv

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// 2->1 multiplexer template
2+
module mux2 (
3+
input logic d0, // Data input 0
4+
input logic d1, // Data input 1
5+
input logic sel, // Select input
6+
output logic z // Output
7+
);
8+
9+
logic out1, out2, out3, out4, out5, out6, out7;
10+
11+
NOT #(.Tpdhl(7), .Tpdlh(10)) g1 (
12+
.Z(out1), .A(d0));
13+
14+
NOT #(.Tpdhl(7), .Tpdlh(10)) g2 (
15+
.Z(out2), .A(d1));
16+
17+
NOT #(.Tpdhl(7), .Tpdlh(10)) g3 (
18+
.Z(out3), .A(sel));
19+
20+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g4 (
21+
.Z(out4), .A(out1), .B(sel));
22+
23+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g5 (
24+
.Z(out5), .A(out2), .B(out3));
25+
26+
NOT #(.Tpdhl(7), .Tpdlh(10)) g6 (
27+
.Z(out6), .A(out4));
28+
29+
NOT #(.Tpdhl(7), .Tpdlh(10)) g7 (
30+
.Z(out7), .A(out5));
31+
32+
OR2 #(.Tpdhl(3), .Tpdlh(2)) g8 (
33+
.Z(z), .A(out6), .B(out7));
34+
35+
endmodule

simulator1/mux4.sv

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 4->1 multiplexer template
2+
module mux4 (
3+
input logic d0, // Data input 0
4+
input logic d1, // Data input 1
5+
input logic d2, // Data input 2
6+
input logic d3, // Data input 3
7+
input logic [1:0] sel, // Select input
8+
output logic z // Output
9+
);
10+
11+
logic out1, out2;
12+
13+
mux2 mux_1(
14+
.d0(d0), .d1(d1), .sel(sel[0]), .z(out1)
15+
);
16+
17+
mux2 mux_2(
18+
.d0(d2), .d1(d3), .sel(sel[0]), .z(out2)
19+
);
20+
21+
mux2 mux_3(
22+
.d0(out1), .d1(out2), .sel(sel[1]), .z(z)
23+
);
24+
endmodule

0 commit comments

Comments
 (0)