I'm trying to do the following let's say bit extension in a generic way.
First Considering B signal with an even number of bits (NBITS). here is an example:
B = 10100011
Second, adding a zero bit to LSB
B1 = 101000110
Finally, By doing an extension I mean repeating even indexed bits (Bold ones) except for the LSB (0) and MSB ones as:
V= 101 100 001 110
I tried this but it's not working:
process(B1)
variable j: integer :=0;
begin
for I in 0 to (NBITS-2) loop
if (I mod 2)=0 then
j:=j+3;
S(j-1 downto j-3) <= B1(I+2 downto I);
end if;
end loop;
end process;
I appreciate any help...
EDIT:
Consider NBITS=8 as the given example, I get this error during simulation, While clearly i'm not reaching to 14 for varaible j!
# ** Fatal: (vsim-3734) Index value 14 is out of range 11 downto 0.
# Time: 0 ps Iteration: 1 Process: /tb_booth_encoder/t1/line__37 File: /home/ms20.58/LAB02/P4ADDER/vhdlsim/BOOTH_ENCODER.vhd
# Fatal error in ForLoop loop at /home/ms20.58/LAB02/P4ADDER/vhdlsim/BOOTH_ENCODER.vhd line 43
#
EDIT
Here is the full code:
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
---------
entity BOOTH_ENCODER is
generic (NBITS :integer := 8
);
Port (
B: In std_logic_vector(NBITS-1 downto 0) ;
S: Out std_logic_vector((3*(NBITS/2)-1) downto 0));
end BOOTH_ENCODER;
---------
architecture BOOTH_ENCODER_BEHAVIORAL of BOOTH_ENCODER is
signal B1: std_logic_vector(NBITS downto 0); --Input with extra 0 at LSB
begin
B1 <= B & '0'; --Extension of bit for encoding
process(B1)
variable j: integer :=0;
begin
for I in 0 to (NBITS-2) loop
if (I mod 2)=0 then
j:=j+3;
S(j-1 downto j-3) <= B1(I+2 downto I);
end if;
end loop;
end process;
end BOOTH_ENCODER_BEHAVIORAL;
```