-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALU_test.v
95 lines (70 loc) · 2.09 KB
/
ALU_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
`include"alu_16bit.v"
module ALU_test();
reg [15:0] a,b;
reg [6:0] select;
wire CF,NF,ZF;
wire [15:0] out;
reg En;
alu_16bit inst(.FirstOperand(a),.SeconedOperand(b),.OP(select),.CarryFlag(CF),.NegativeFlag(NF),.ZeroFlag(ZF),.Result(out),.En(En));
initial begin
En=1;
a=16'hFFFF;
b=16'h0001;
select=7'b000_0001;
#5
if(out==0 && CF==1 && ZF==1 && NF == 0 )
$display("success:a=%b + b=%b = res=%b ZF=%b CF=%b NF=%b",a,b,out,ZF,CF,NF);
else
$display("failre:a=%b + b=%b = res=%b ZF=%b CF=%b NF=%b",a,b,out,ZF,CF,NF);
En=0;
a=16'h0001;
b=16'h0001;
select=7'b000_0001;
#5
if(out==0 && CF==1 && ZF==1 && NF == 0 )
$display("success:a=%b + b=%b = res=%b ZF=%b CF=%b NF=%b",a,b,out,ZF,CF,NF);
else
$display("failre:a=%b + b=%b = res=%b ZF=%b CF=%b NF=%b",a,b,out,ZF,CF,NF);
En=1;
a=16'hFFFF;
b=16'h0001;
select=7'b000_0100;
#5
if(out==0 && CF==1 && ZF==1 && NF == 0 )
$display("success:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
else
$display("failre:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
a=16'hFFFF;
b=16'h0001;
select=7'b000_0001;
#5
if(out==0 && CF==1 && ZF==1 && NF == 0 )
$display("success:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
else
$display("failre:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
a=16'h0000;
b=16'h0000;
select=7'b000_0001;
#5
if(out==0 && CF==0 && ZF==1 && NF == 0 )
$display("success:a=%b + b=%b = res=%b ZF=%b CF=%b NF=%b",a,b,out,ZF,CF,NF);
else
$display("failre:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
a=16'b1000_0000_0000_0000;
b=16'h0001;
select=7'b001_0000;
#5
if(out==16'b0111_1111_1111_1111 && CF==0 && ZF==0 && NF == 0 )
$display("success:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
else
$display("failer:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
a=16'b0000_0000_0000_0000;
b=16'h0001;
select=7'b001_0000;
#5
if(out==16'b1111_1111_1111_1111 && CF==0 && ZF==0 && NF == 1 )
$display("success:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
else
$display("failre:a=%b res=%b ZF=%b CF=%b NF=%b",a,out,ZF,CF,NF);
end
endmodule