Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to Write verilog for selecting part of bus

Status
Not open for further replies.

jfzhan

Newbie level 4
Newbie level 4
Joined
Apr 25, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,352
Dear all,

There are bus A[0:100] ,B[0:15], and the register length[3:0].
The register length can be set by user.
If the length = 0, the B[0:15] = A[0:15],
If the length = 1, the B[0:15] = A[1:16],
If the length = 2, the B[0:15] = A[2:17],
If the length = 3, the B[0:15] = A[3:18], and so on.

can I write like this,
assign s_point = length;
assign e_point = length + 15;
assign B[0:15] = A[s_point:e_point];

The best method is the following method?

always@(length or A) begin
case(length)
0 : B[0:15] = A[0:15];
1 : B[0:15] = A[1:15];
2 : B[0:15] = A[2:15];
...
15 : B[0:15] = A[15:30];
endcase
end

Does there have any good method to write??

Thanks!!
 

feel_on_on

Full Member level 5
Full Member level 5
Joined
Apr 29, 2005
Messages
283
Helped
6
Reputation
12
Reaction score
4
Trophy points
1,298
Activity points
3,208
no ,u make a mistake !
 

    jfzhan

    Points: 2
    Helpful Answer Positive Rating

jfzhan

Newbie level 4
Newbie level 4
Joined
Apr 25, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,352
I am sorry! I only want to know how to write it in verilog!
 

BrownBear

Junior Member level 1
Junior Member level 1
Joined
Mar 21, 2005
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,437
I believe that the optimal way is

always@(length or A) begin
case(length)
0 : B[0:15] = A[0:15];
1 : B[0:15] = A[1:15];
2 : B[0:15] = A[2:15];
...
15 : B[0:15] = A[15:30];
endcase
end
 

jfzhan

Newbie level 4
Newbie level 4
Joined
Apr 25, 2005
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,352
yes. I think only the second method is a good method.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top