D = (X - Bi) - Y

Bi는 아래 자리에 빌려준 값. 입력이 된다.

위에서 빌린 수는 B로 표현되고, 진리표를 작성해보면 쉽다.




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
45
46
47
48
49
50
51
52
53
54
55
--
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
 
 
entity FullSubtractor_vhdl is
 
    port (
        X, Y, bi    :   in  integer range 0 to 1;
        D, B        :   out std_logic
    );
 
end FullSubtractor_vhdl;
 
 
architecture arc of FullSubtractor_vhdl is
 
    signal  diff    :   integer range -2 to 1;
 
begin
 
    process(X, Y, bi)
    begin
     
        diff <= X - bi - Y;
         
        if diff = -2 then       -- XYbi = 011
 
            D   <=   '0';
            B   <=   '1';
             
        elsif diff = -1 then    -- XYbi = 001, 010, 111
         
            D   <=   '1';
            B   <=   '1';
             
        elsif diff = 0 then     -- XYbi = 000, 101, 110
         
            D   <=   '0';
            B   <=   '0';
             
        else                    -- XYbi = 100
         
            D   <=   '1';
            B   <=   '0';
             
        end if;
 
     
    end process;
 
 
end arc;



Posted by 쿨한넘