-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_shift.v
More file actions
88 lines (83 loc) · 1.95 KB
/
universal_shift.v
File metadata and controls
88 lines (83 loc) · 1.95 KB
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
//
// Engineer: Utkarsha
//
// Create Date: 05.01.2024 11:12:01
// Design Name: universal_shift.v
// Module Name: universal_shift
// Project Name: 5-bit Universal Shift Register
//
// Description: This Verilog project implements a 5-bit Universal Shift Register capable of performing four operations based on a 2-bit select input: no change, shift left, shift right, and parallel load.
// The universal_shift module takes a parallel input (PI), serial input (SI), and outputs both parallel (PO) and serial output (SO) based on the operation selected.
// It supports synchronous operation with clock and reset control.
// The provided testbench (universal_shift_tb) simulates various scenarios to validate functionality, including edge cases for shifting and loading.
// This module is useful in digital systems that require flexible data manipulation and is a common building block in processors and communication systems.
//
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module universal_shift(PO, PI, SI, SO, sel, clk, rst);
input [1:0] sel;
input [4:0] PI;
input SI, rst, clk;
output reg [4:0]PO;
output SO;
always @(posedge clk)
if(rst)
PO<=0;
else
case(sel)
2'b00 : PO<=PO;
2'b01 : PO<={PO[3:0], SI};
2'b10 : PO<={SI, PO[4:1]};
2'b11 : PO<=PI;
default : PO<=0;
endcase
assign SO = (sel == 2'b01)?PO[4]:PO[0];
endmodule
module universal_shift_tb;
reg sel,PI,SI,rst,clk;
wire PO,SO;
universal_shift b1(PO, PI, SI, SO, sel, clk, rst);
initial
begin
clk = 0;
forever #20 clk = ~clk;
end
initial
begin
sel = 00;
PI = 01101;
SI = 1;
rst = 0;
#40;
sel = 01;
PI = 01001;
SI = 1;
rst = 0;
#40;
sel = 10;
PI = 01001;
SI = 0;
rst = 0;
#40;
sel = 11;
PI = 01001;
SI = 1;
rst = 0;
#40;
sel = 01;
PI = 01001;
SI = 1;
rst = 1;
#40;
sel = 01;
PI = 01001;
SI = 0;
rst = 0;
#40;
$finish;
end
endmodule