OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [alu/] [test_slice.sv] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
//==============================================================
2
// Test ALU slice
3
//==============================================================
4
`timescale 100 ns/ 100 ns
5
 
6
module test_slice;
7
 
8
// ----------------- INPUT -----------------
9
reg [3:0] op1_sig;          // Operand 1
10
reg [3:0] op2_sig;          // Operand 2
11
reg cy_in_sig;              // Carry in (to slice D)
12
reg R_sig;                  // Operation control "R"
13
reg S_sig;                  // Operation control "S"
14
reg V_sig;                  // Operation control "V"
15
 
16
// ----------------- OUTPUT -----------------
17
wire cy_out_sig;            // Carry out (from slice A)
18
wire [3:0] result_sig;      // Result bits
19
 
20
// ----------------- CONNECTIONS -----------------
21
wire cy_out_D_sig;          // Carry out from slice D into slice C
22
wire cy_out_C_sig;          // Carry out from slice C into slice B
23
wire cy_out_B_sig;          // Carry out from slice B into slice A
24
 
25
// ----------------- TEST -------------------
26
`define CHECK(arg) \
27
   assert(result_sig==arg);
28
 
29
initial begin
30
    op1_sig = '0;
31
    op2_sig = '0;
32
    cy_in_sig = 0;
33
    R_sig = 0;
34
    S_sig = 0;
35
    V_sig = 0;
36
 
37
    //------------------------------------------------------------
38
    // Test ADD/ADC:    R=0  S=0  V=0    Cin for ADC operation
39
    R_sig = 0;
40
    S_sig = 0;
41
    V_sig = 0;
42
        op1_sig = 4'h0;     // 0 + 0 + 0 = 0
43
        op2_sig = 4'h0;
44
        cy_in_sig = 0;
45
    #1 `CHECK(0);
46
        cy_in_sig = 1;      // 0 + 0 + 1 = 1
47
    #1 `CHECK(1);
48
        op1_sig = 4'h2;     // 2 + 8 + 0 = A
49
        op2_sig = 4'h8;
50
        cy_in_sig = 0;
51
    #1 `CHECK(4'hA);
52
        cy_in_sig = 1;      // 2 + 8 + 1 = B
53
    #1 `CHECK(4'hB);
54
        op1_sig = 4'hB;     // B + 4 + 0 = F
55
        op2_sig = 4'h4;
56
        cy_in_sig = 0;
57
    #1 `CHECK(4'hF);
58
        cy_in_sig = 1;      // B + 4 + 1 = 0 + CY
59
    #1 `CHECK(4'h0);
60
        op1_sig = 4'hD;     // D + 6 + 0 = 3 + CY
61
        op2_sig = 4'h6;
62
        cy_in_sig = 0;
63
    #1 `CHECK(4'h3);
64
        cy_in_sig = 1;      // D + 6 + 1 = 4 + CY
65
    #1 `CHECK(4'h4);
66
 
67
    //------------------------------------------------------------
68
    // Test XOR:        R=1  S=0  V=0  Cin=0
69
    #1
70
    R_sig = 1;
71
    S_sig = 0;
72
    V_sig = 0;
73
    cy_in_sig = 0;
74
        op1_sig = 4'h0;     // 0 ^ 0 = 0
75
        op2_sig = 4'h0;
76
    #1 `CHECK(4'h0);
77
        op1_sig = 4'h3;     // 3 ^ C = F
78
        op2_sig = 4'hC;
79
    #1 `CHECK(4'hF);
80
        op1_sig = 4'h6;     // 6 ^ 3 = 5
81
        op2_sig = 4'h3;
82
    #1 `CHECK(4'h5);
83
        op1_sig = 4'hF;     // F ^ F = 0
84
        op2_sig = 4'hF;
85
    #1 `CHECK(4'h0);
86
 
87
    //------------------------------------------------------------
88
    // Test AND:        R=0  S=1  V=0  Cin=1
89
    #1
90
    R_sig = 0;
91
    S_sig = 1;
92
    V_sig = 0;
93
    cy_in_sig = 1;
94
        op1_sig = 4'h0;     // 0 & 0 = 0
95
        op2_sig = 4'h0;
96
    #1 `CHECK(4'h0);
97
        op1_sig = 4'h3;     // 3 & C = 0
98
        op2_sig = 4'hC;
99
    #1 `CHECK(4'h0);
100
        op1_sig = 4'h6;     // 6 & 3 = 2
101
        op2_sig = 4'h3;
102
    #1 `CHECK(4'h2);
103
        op1_sig = 4'hF;     // F & F = F
104
        op2_sig = 4'hF;
105
    #1 `CHECK(4'hF);
106
 
107
    //------------------------------------------------------------
108
    // Test OR:         R=1  S=1  V=1  Cin=0
109
    #1
110
    R_sig = 1;
111
    S_sig = 1;
112
    V_sig = 1;
113
    cy_in_sig = 0;
114
        op1_sig = 4'h0;     // 0 | 0 = 0
115
        op2_sig = 4'h0;
116
    #1 `CHECK(4'h0);
117
        op1_sig = 4'h3;     // 3 | C = F
118
        op2_sig = 4'hC;
119
    #1 `CHECK(4'hF);
120
        op1_sig = 4'h6;     // 6 | 3 = 7
121
        op2_sig = 4'h3;
122
    #1 `CHECK(4'h7);
123
        op1_sig = 4'hF;     // F | F = F
124
        op2_sig = 4'hF;
125
    #1 `CHECK(4'hF);
126
 
127
    #1 $display("End of test");
128
end
129
 
130
//--------------------------------------------------------------
131
// Instantiate 4 ALU slice units, daisy-chained; MSB is slice A
132
//
133
//            slice_A slice_B slice_C slice_D
134
//  cy_out <=   [3]     [2]     [1]     [0]  <= cy_in
135
//--------------------------------------------------------------
136
alu_slice slice_A
137
(
138
    .op1(op1_sig[3]) ,          // input  op1_sig
139
    .op2(op2_sig[3]) ,          // input  op2_sig
140
    .cy_in(cy_out_B_sig) ,      // input  cy_in_sig
141
    .R(R_sig) ,                 // input  R_sig
142
    .S(S_sig) ,                 // input  S_sig
143
    .V(V_sig) ,                 // input  V_sig
144
    .cy_out(cy_out_sig) ,       // output  cy_out_sig
145
    .result(result_sig[3])      // output  result_sig
146
);
147
 
148
alu_slice slice_B
149
(
150
    .op1(op1_sig[2]) ,          // input  op1_sig
151
    .op2(op2_sig[2]) ,          // input  op2_sig
152
    .cy_in(cy_out_C_sig) ,      // input  cy_in_sig
153
    .R(R_sig) ,                 // input  R_sig
154
    .S(S_sig) ,                 // input  S_sig
155
    .V(V_sig) ,                 // input  V_sig
156
    .cy_out(cy_out_B_sig) ,     // output  cy_out_sig
157
    .result(result_sig[2])      // output  result_sig
158
);
159
 
160
alu_slice slice_C
161
(
162
    .op1(op1_sig[1]) ,          // input  op1_sig
163
    .op2(op2_sig[1]) ,          // input  op2_sig
164
    .cy_in(cy_out_D_sig) ,      // input  cy_in_sig
165
    .R(R_sig) ,                 // input  R_sig
166
    .S(S_sig) ,                 // input  S_sig
167
    .V(V_sig) ,                 // input  V_sig
168
    .cy_out(cy_out_C_sig) ,     // output  cy_out_sig
169
    .result(result_sig[1])      // output  result_sig
170
);
171
 
172
alu_slice slice_D
173
(
174
    .op1(op1_sig[0]) ,          // input  op1_sig
175
    .op2(op2_sig[0]) ,          // input  op2_sig
176
    .cy_in(cy_in_sig) ,         // input  cy_in_sig
177
    .R(R_sig) ,                 // input  R_sig
178
    .S(S_sig) ,                 // input  S_sig
179
    .V(V_sig) ,                 // input  V_sig
180
    .cy_out(cy_out_D_sig) ,     // output  cy_out_sig
181
    .result(result_sig[0])      // output  result_sig
182
);
183
 
184
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.