1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | USE IEEE.STD_LOGIC_UNSIGNED.ALL;
|
4 | USE IEEE.numeric_std.ALL;
|
5 | ENTITY calc is
|
6 | Port (Num1: in Signed (1 downto 0);
|
7 | Num2: in Signed (1 downto 0);
|
8 | S: in STD_LOGIC_VECTOR (1 downto 0);
|
9 | a_to_g:out STD_LOGIC_VECTOR (6 downto 0));
|
10 | end calc;
|
11 |
|
12 | Architecture tris of calc is
|
13 | signal SUM:Signed (4 downto 0);
|
14 | signal RES:Signed (4 downto 0);
|
15 | signal MUL:Signed (4 downto 0);
|
16 | signal COM:Signed (4 downto 0);
|
17 | signal DISP : signed(4 downto 0);
|
18 | begin
|
19 | process(Num1,Num2,S)
|
20 | BEGIN
|
21 | CASE S IS
|
22 | WHEN "00"=>SUM<=resize(Num1,5)+Num2;
|
23 | WHEN "01"=>RES<=resize(Num1,5)-Num2;
|
24 | WHEN "10"=>
|
25 | if Num1>Num2 then
|
26 | COM <= "11110";
|
27 | elsif Num1<Num2 then
|
28 | COM <= "11011";
|
29 | else
|
30 | COM <= "11010";
|
31 | end if;
|
32 | WHEN OTHERS=>MUL<=resize(Num1,3)*Num2;
|
33 | END CASE;
|
34 | END PROCESS;
|
35 | PROCESS (S,SUM,RES,MUL,COM)
|
36 | BEGIN
|
37 | IF (S="00") THEN DISP<=SUM;
|
38 | ELSIF (S="01") THEN DISP<=RES;
|
39 | ELSIF (S="10") THEN DISP<=COM;
|
40 | ELSE DISP<=MUL;
|
41 | END IF;
|
42 | END PROCESS;
|
43 |
|
44 | process (DISP)
|
45 | begin
|
46 | case DISP is
|
47 | -- output numbers
|
48 | when "00000"=> a_to_g <="0000001"; --0
|
49 | when "00001"=> a_to_g <="1001111"; --1
|
50 | when "00010"=> a_to_g <="0010010"; --2
|
51 | when "00011"=> a_to_g <="0000110"; --3
|
52 | when "00100"=> a_to_g <="1001100"; --4
|
53 | when "00101"=> a_to_g <="0100100"; --5
|
54 | when "00110"=> a_to_g <="0100000"; --6
|
55 | when "00111"=> a_to_g <="0001101"; --7
|
56 | when "01000"=> a_to_g <="0000000"; --8
|
57 | when "01001"=> a_to_g <="0000100"; --9
|
58 | -- output symbols
|
59 | when "11010"=> a_to_g <="1000001"; --=
|
60 | when "11011"=> a_to_g <="1001110"; --<
|
61 | when "11110"=> a_to_g <="1111000"; -->
|
62 | when others => a_to_g <="0000000";
|
63 | end case;
|
64 | end process;
|
65 | end tris;
|