Bit Numbering in Verilog

427 views
Skip to first unread message

Tom Szolyga

unread,
Oct 18, 2021, 2:09:13 PM10/18/21
to
I am working on creating a FPGA implementation of a IBM 7000 series CPU. The bits are numbered with bit 0 as the most significant bit and bit n (n bits per word) as the least significant. Verilog seems to want the opposite order: bit 0 is the least significant bit.

Does anyone know or has anyone tried numbering bits the other way around in Verilog?

Thanks,
Tom

Julio Di Egidio

unread,
Oct 18, 2021, 4:57:28 PM10/18/21
to
On Monday, 18 October 2021 at 20:09:13 UTC+2, tszo...@pacbell.net wrote:
> I am working on creating a FPGA implementation of a IBM 7000 series CPU. The bits are numbered with bit 0 as the most significant bit and bit n (n bits per word) as the least significant. Verilog seems to want the opposite order: bit 0 is the least significant bit.
>
> Does anyone know or has anyone tried numbering bits the other way around in Verilog?

There is no such preference in Verilog: dimensions can be [7:0] as well as [0:7], plus you do the wiring...

HTH,

Julio

siso

unread,
Nov 8, 2021, 10:57:30 AM11/8/21
to
I guess one has to be careful here. Not sure whether a bit slicing is relevant to your question, nevertheless - here is the example:
wire[31: 0] vA; // OK
wire[ 0: 7] vX; //OK
assign vx = vA[0:7]; //this one will yield and error most likely: Reverse part-select index ordering.
You can't do reverse slice indexing. The indexes shall follow the order of declaration.
If something of the kind above is required - I don't know a better way of doing it, but using explicit assign bit by bit or (of course) in a cycle etc.
Regards
Svilen

gnuarm.del...@gmail.com

unread,
Nov 20, 2021, 9:26:00 AM11/20/21
to
On Monday, October 18, 2021 at 2:09:13 PM UTC-4, tszo...@pacbell.net wrote:
> I am working on creating a FPGA implementation of a IBM 7000 series CPU. The bits are numbered with bit 0 as the most significant bit and bit n (n bits per word) as the least significant. Verilog seems to want the opposite order: bit 0 is the least significant bit.
>
> Does anyone know or has anyone tried numbering bits the other way around in Verilog?

Yes, use VHDL. Bit ordering is user defined in VHDL. The libraries you use are not always general enough to work with reverse bit ordering, but many will work fine.

Can you use the reverse bit ordering for the external interface and use conventional bit ordering for everything internal? I suppose your instruction memory will want to be IBM ordered... which btw, I think you made a typo. It will range [0 to n-1], not [0 to n]. I believe there were some truly deranged companies that used [1 to n] bit ordering.

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Kevin

unread,
Jun 2, 2022, 11:08:38 AM6/2/22
to
> wire[31: 0] vA; // OK
> wire[ 0: 7] vX; //OK
> assign vx = vA[0:7]; //this one will yield and error most likely: Reverse part-select index ordering.
> You can't do reverse slice indexing. The indexes shall follow the order of declaration.

You can use the streaming operator to flip a vector:
assign vx = {<<{vA[7:0]}};
Reply all
Reply to author
Forward
0 new messages