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.

modulo operator in vhdl

mdreus

Newbie
Joined
Jun 23, 2023
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
32
I want to do a calculation of the mod operator in vhdl for modules (2^n)-1, (2^n)+1 and for modules (2^n)+k and (2^n)-k for k=3, 5, 11, 21, 85, 341, etc. The operations would be f = (X*Y) mod ((2^n)-1) for example.

For example for n=8 bits it worked, but for bits equal to or above 16 bits it doesn't work, can anyone tell me why it doesn't work and how to improve my code to make it work.

My code for n = 8 bits, module 255

library IEEE;
use IEEE.numeric_std.all;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity top is
port(
R0 : out integer range 0 to 254;
Y : in integer range 0 to 254;
X : in integer range 0 to 254);

end top;
architecture structural of top is
begin
R0 <= (X * Y) mod 255;
end structural;

My code for n = 16 bits, module 65535

library IEEE;
use IEEE.numeric_std.all;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity top is
port(
R0 : out integer range 0 to 65534;
Y : in integer range 0 to 65534;
X : in integer range 0 to 65534);

end top;

architecture structural of top is
begin
R0 <= (X * Y) mod 65535;
end structural;

n = 8 bits, (254 * 253) mod 255 = 2 right
n = 16 bits, (65534 * 65533) mod 65535 = 1 wrong, it was supposed to give 2
 

Attachments

  • modelsim2nmenos18bits.png
    modelsim2nmenos18bits.png
    128.6 KB · Views: 59
  • modelsim2nmenos116bits.png
    modelsim2nmenos116bits.png
    127.3 KB · Views: 54

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top