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.

vhdl code for multiplicative inverse modulo 2^4+1

Status
Not open for further replies.

manasa4

Newbie level 3
Joined
Feb 25, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
hello,can any one explain how to get multiplicative inverse for 4 bit input,i.e,for modulo 17(2^4+1),i have written a code but its not being run ,
number in integer multiplicative inverse\
0 0
1 1
2 9
3 6
4 13
5 7
6 3
7 5
8 15
9 2
10 12
11 14
12 10
13 4
14 11
15 8



Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
entity mulinv is
port(x:in std_logic_vector(3 downto 0);
      z:out std_logic_vector(3 downto 0));
end mulinv;
 
architecture Behavioral of mulinv is
signal xi,zi,t1,t2,y,q:integer;                              
begin
process(x)
begin
xi<=conv_integer(x);
t2<=1;
 if (xi=1) then zi<=1;
 elsif (xi=0) then zi<=0;
 else
   t1<=17/xi;
   y<=17 mod xi;
   if(y=1) then zi<=(1-t1);
    else
        while (y/=1) loop
             q<=xi/y;
            xi<=xi mod y;
             t2<=t2+(q*t1);
             if xi=1 then zi<=t2;
             else  q<=y/xi;
                   y<=y mod xi;
                     t1<=t1+(q*t2);
 
              end if;
             end loop; 
 
         end if;
  zi<=(1-t1);
 end if ;
 
z<=conv_std_logic_vector(zi,4);
end process;    
  
end Behavioral;

 
Last edited by a moderator:

but its not being run
What do you mean? the code isn't synthesizable, because the iteration count can't be determined by the synthesis tool?
 

at 4b, the best choice will be a lookup table. you can declare that as a constant in VHDL for this size.
Code:
 type int_array is array (natural range <>) of integer;
constant MULT_INV : int_array(0 to 15) := (0,1,9,6,13,7,3,5,15,2,12,14,10,4,11,8 );
signal x : integer range 0 to 15;
signal y : integer range 0 to 15;
...

y <= MULT_INV(x);

assuming the numbers you provided were correct.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top