0111- 0011 เอา 0011 ไป invert 1100 แล้วบวก 1 = 1101
0111(6)+1101(-3) = 0011(3)
cr.http://cpre.kmutnb.ac.th/esl
CODE:
library ieee;
use ieee.std_logic_1164.all;
entity full_add is
port(
a , b, c_in : in std_logic;
sub : in std_logic;
c_out, p : out std_logic);
end full_add;
architecture data_flow of full_add is
signal keep :std_logic;
begin
process(a,b,c_in)
begin
keep <= b xor sub;
c_out <= ((a xor keep) and c_in) or (a and keep);
p <= (a xor keep) xor c_in;
end process;
end data_flow;