ayush15
Newbie level 4
- Joined
- Sep 13, 2013
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 66
I am trying to write a synthesisable VHDL code for the mod operation in VHDL. Since the mod operation is not synthesisable for operands other than powers of 2, a separate code needs to be written. I want to perform mod operation on a 8-bit number by 5. I have tried the code below but this does not work.
I have also tried the code below but this too doesn't works.
Please help me regarding this mod operation.
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity modop is
port(x: in std_logic_vector(7 downto 0);
r:out integer
);
end modop;
architecture Behavioral of modop is
begin
process(x)
variable s1,s2: integer:= 0;
variable n,s3: integer:= 1;
begin
s1:= to_integer(unsigned(x));
while s3>0 loop
s2:= 5*n;
s3:= s1-s2;
if s3=0 then
r<=0;
elsif s3<0 then
r<= s3+5;
elsif s3>0 then
n:=n+1;
end if;
end loop;
end process;
end Behavioral;
I have also tried the code below but this too doesn't works.
Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity modop is
port(x: in std_logic_vector(7 downto 0);
r:out unsigned(7 downto 0)
);
end modop;
architecture Behavioral of modop is
signal s4:unsigned(7 downto 0):= "11111011";
signal s5: unsigned(7 downto 0):= "00000101";
begin
process(x)
variable s1,s2:unsigned(7 downto 0):="00000000";
variable s3: integer:= 1;
begin
s1:= unsigned(x);
while s3>0 loop
s2:= s1+s4;
s3:= to_integer(s2);
end loop;
r<= s2+s5;
end process;
end Behavioral;
Please help me regarding this mod operation.