Professional Documents
Culture Documents
MSSV: 41801040
b/
entity bai1 is
port (CLK, X1, X2 : in bit;
Z1, Z2 ; out bit);
end bai1;
architecture bailam of bai1 is
type states is {S0, S1, S2, S3};
signal state, next_state : states;
begin
process (X1, X2, state)
begin
Z1 <= ‘0’; Z2 <= ‘0’;
case state is
when S0 => if (X1 = ‘0’) then
if (X2 = ‘0’) then
next_state <= S3;
else
next_state <= S2;
end if;
else
if (X2 = ‘0’) then
Z1 <= ‘1’;
Z2 <= ‘1’;
next_state <= S1;
else
Z2 <= ‘1’;
next_state <= S0;
end if
end if;
when S1 => if (X1 = ‘0’) then
Z1 <= ‘1’;
if (X2 = ‘0’) then
next_state <= S0;
else
next_state <= S1;
end if;
else
Z1 <= ‘1’; Z2 <= ‘1’;
if (X2 = ‘0’) then
next_state <= S2;
else
next_state <= S3;
end if
end if;
when S2 => if (X1 = ‘0’) then
if (X2 = ‘0’) then
next_state <= S3;
else
Z1 <= ‘1’;
next_state <= S0;
end if;
else
next_state <= S1;
Z2 <= ‘1’
if (X2 = ‘0’) then
Z1 <= ‘1’;;
end if
end if;
when S3 => if (X1 = ‘0’) then
next_state <= S2;
else
if (X2 = ‘0’) then
Z2 <= ‘1’;
next_state <= S1;
else
Z2 <= ‘1’;
next_state <= S0;
end if
end if;
end case;
end process;
process (CLK)
begin
if (CLK = ‘1’ and CLK’event) then
state <= next_state;
end if;
end process;
end bailam;
5.2
5.15
a/
library ieee;
use ieee.std_logic_1164.all;
entity bai3 is
port (
X1,X2,X3,CLK : in bit;
Z1,Z2,Z3 : out bit;
);
end bai3;
process (CLK)
begin
if(CLK'EVENT and CLK = '0') then
state <= nextstate;
end if;
end process;
end bailam3;