-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArithmeticLogicUnitSimulation.v
68 lines (59 loc) · 2 KB
/
ArithmeticLogicUnitSimulation.v
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Mustafa Bozdoğan, Enes Saçak
//////////////////////////////////////////////////////////////////////////////////
module ArithmeticLogicUnitSimulation();
reg[15:0] A, B;
reg[4:0] FunSel;
reg WF;
wire[15:0] ALUOut;
wire[3:0] FlagsOut;
integer test_no;
wire Z, C, N, O;
CrystalOscillator clk();
ArithmeticLogicUnit ALU( .A(A), .B(B), .FunSel(FunSel), .WF(WF),
.Clock(clk.clock), .ALUOut(ALUOut), .FlagsOut(FlagsOut));
FileOperation F();
assign {Z,C,N,O} = FlagsOut;
initial begin
F.SimulationName ="ArithmeticLogicUnit";
F.InitializeSimulation(0);
clk.clock = 0;
//Test 1
test_no = 1;
A = 16'h1234;
B = 16'h4321;
ALU.FlagsOut = 4'b1111;
FunSel =5'b10100;
WF =1;
#5
F.CheckValues(ALUOut,16'h5555, test_no, "ALUOut");
F.CheckValues(Z,1, test_no, "Z");
F.CheckValues(C,1, test_no, "C");
F.CheckValues(N,1, test_no, "N");
F.CheckValues(O,1, test_no, "O");
//Test 2
test_no = 2;
clk.Clock();
F.CheckValues(ALUOut,16'h5555, test_no, "ALUOut");
F.CheckValues(Z,0, test_no, "Z");
F.CheckValues(C,0, test_no, "C");
F.CheckValues(N,0, test_no, "N");
F.CheckValues(O,0, test_no, "O");
//Test 3
test_no = 3;
A = 16'h7777;
B = 16'h8889;
ALU.FlagsOut = 4'b0000;
FunSel =5'b10101;
WF =1;
#5
clk.Clock();
F.CheckValues(ALUOut,16'h0001, test_no, "ALUOut");
F.CheckValues(Z,1, test_no, "Z");
F.CheckValues(C,1, test_no, "C");
F.CheckValues(N,0, test_no, "N");
F.CheckValues(O,0, test_no, "O");
F.FinishSimulation();
end
endmodule