Mode:
Duration:
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity Factorial is
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
fact_out : out INTEGER
);
end Factorial;
architecture Behavioral of Factorial is
signal fact : INTEGER := 1;
signal counter : INTEGER := 1;
constant N : INTEGER := 5;
begin
process(clk, reset)
begin
if reset = '1' then
fact <= 1;
counter <= 1;
elsif rising_edge(clk) then
if counter <= N then
fact <= fact * counter;
counter <= counter + 1;
end if;
end if;
end process;
fact_out <= fact;
end Behavioral;Coding works best on desktop or with an external keyboard.