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
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!!
 

no ,u make a mistake !
 

    jfzhan

    Points: 2
    Helpful Answer Positive Rating
I am sorry! I only want to know how to write it in verilog!
 

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
 

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

Back
Top