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

Subversion Repositories a-z80

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
//==============================================================
2
// Test ALU shifter core block
3
//==============================================================
4
`timescale 100 ns/ 100 ns
5
 
6
module test_shifter_core;
7
 
8
// ----------------- INPUT -----------------
9
logic [7:0] db;                 // Input data bus
10
logic shift_in;                 // Input bit to be shifted in
11
logic shift_left;               // Input control to left-shift
12
logic shift_right;              // Input control to right-shift
13
 
14
// ----------------- OUTPUT -----------------
15
wire shift_db0;                 // db[0] for shift logic
16
wire shift_db7;                 // db[7] for shift logic
17
wire [3:0] out_high;            // To internal ALU bus, high nibble
18
wire [3:0] out_low;             // ..low nibble
19
 
20
// ----------------- TEST -------------------
21
`define CHECK(arg) \
22
   assert({out_high,out_low}==arg);
23
 
24
initial begin
25
    db = 8'h00;
26
    shift_left = 0;
27
    shift_right = 0;
28
    shift_in = 0;
29
 
30
    //------------------------------------------------------------
31
    // Test load without shifting
32
        db = 8'hAA;
33
    #1 `CHECK(8'hAA);
34
        db = 8'h55;
35
    #1 `CHECK(8'h55);
36
 
37
    //------------------------------------------------------------
38
    // Test right shift, no carry-in
39
    #1  db =  8'b00000001;
40
        shift_right = 1;
41
        shift_in = 0;
42
    #1 `CHECK(8'b00000000);
43
        db =  8'b00000010;
44
    #1 `CHECK(8'b00000001);
45
        db =  8'b00000100;
46
    #1 `CHECK(8'b00000010);
47
        db =  8'b00001000;
48
    #1 `CHECK(8'b00000100);
49
        db =  8'b00010000;
50
    #1 `CHECK(8'b00001000);
51
        db =  8'b00100000;
52
    #1 `CHECK(8'b00010000);
53
        db =  8'b01000000;
54
    #1 `CHECK(8'b00100000);
55
        db =  8'b10000000;
56
    #1 `CHECK(8'b01000000);
57
 
58
    // With carry-in
59
    #1  db =  8'b00000001;
60
        shift_in = 1;
61
    #1 `CHECK(8'b10000000);
62
        db =  8'b00000010;
63
    #1 `CHECK(8'b10000001);
64
        db =  8'b00000100;
65
    #1 `CHECK(8'b10000010);
66
        db =  8'b00001000;
67
    #1 `CHECK(8'b10000100);
68
        db =  8'b00010000;
69
    #1 `CHECK(8'b10001000);
70
        db =  8'b00100000;
71
    #1 `CHECK(8'b10010000);
72
        db =  8'b01000000;
73
    #1 `CHECK(8'b10100000);
74
        db =  8'b10000000;
75
    #1 `CHECK(8'b11000000);
76
 
77
    //------------------------------------------------------------
78
    // Test left shift, no carry-in
79
    #1  db =  8'b00000001;
80
        shift_right = 0;
81
        shift_left = 1;
82
        shift_in = 0;
83
    #1 `CHECK(8'b00000010);
84
        db =  8'b00000010;
85
    #1 `CHECK(8'b00000100);
86
        db =  8'b00000100;
87
    #1 `CHECK(8'b00001000);
88
        db =  8'b00001000;
89
    #1 `CHECK(8'b00010000);
90
        db =  8'b00010000;
91
    #1 `CHECK(8'b00100000);
92
        db =  8'b00100000;
93
    #1 `CHECK(8'b01000000);
94
        db =  8'b01000000;
95
    #1 `CHECK(8'b10000000);
96
        db =  8'b10000000;
97
    #1 `CHECK(8'b00000000);
98
 
99
    // With carry-in
100
    #1  db =  8'b00000001;
101
        shift_in = 1;
102
    #1 `CHECK(8'b00000011);
103
        db =  8'b00000010;
104
    #1 `CHECK(8'b00000101);
105
        db =  8'b00000100;
106
    #1 `CHECK(8'b00001001);
107
        db =  8'b00001000;
108
    #1 `CHECK(8'b00010001);
109
        db =  8'b00010000;
110
    #1 `CHECK(8'b00100001);
111
        db =  8'b00100000;
112
    #1 `CHECK(8'b01000001);
113
        db =  8'b01000000;
114
    #1 `CHECK(8'b10000001);
115
        db =  8'b10000000;
116
    #1 `CHECK(8'b00000001);
117
 
118
    //------------------------------------------------------------
119
    // Test right shift, no carry-in - special SRA instruction
120
    // This instruction simply duplicates bit [7] instead of using CY
121
    #1  db =  8'b00000001;
122
        shift_right = 1;
123
        shift_left = 0;
124
        shift_in = shift_db7;
125
    #1 `CHECK(8'b10000000);
126
        db =  8'b00000010;
127
    #1 `CHECK(8'b10000001);
128
        db =  8'b00000100;
129
    #1 `CHECK(8'b10000010);
130
        db =  8'b00001000;
131
    #1 `CHECK(8'b10000100);
132
        db =  8'b00010000;
133
    #1 `CHECK(8'b10001000);
134
        db =  8'b00100000;
135
    #1 `CHECK(8'b10010000);
136
        db =  8'b01000000;
137
    #1 `CHECK(8'b10100000);
138
        db =  8'b10000000;
139
    #1 `CHECK(8'b11000000);
140
 
141
    // With carry-in
142
    #1  db =  8'b00000001;
143
        shift_in = 1;
144
    #1 `CHECK(8'b10000000);
145
        db =  8'b00000010;
146
    #1 `CHECK(8'b10000001);
147
        db =  8'b00000100;
148
    #1 `CHECK(8'b10000010);
149
        db =  8'b00001000;
150
    #1 `CHECK(8'b10000100);
151
        db =  8'b00010000;
152
    #1 `CHECK(8'b10001000);
153
        db =  8'b00100000;
154
    #1 `CHECK(8'b10010000);
155
        db =  8'b01000000;
156
    #1 `CHECK(8'b10100000);
157
        db =  8'b10000000;
158
    #1 `CHECK(8'b11000000);
159
 
160
    #1 $display("End of test");
161
end
162
 
163
//--------------------------------------------------------------
164
// Instantiate shifter core block and assign identical nets and variables
165
//--------------------------------------------------------------
166
 
167
alu_shifter_core alu_shifter_core_inst( .* );
168
 
169
endmodule

powered by: WebSVN 2.1.0

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