Build and simulate half subtractor and full subtractor circuits in VHDL

half subtractor and full subtractor

1) Half subtractor:

Circuit:

Truth table:

ABDIFFERENCEBORROW
0000
0110
1011
1100

Code:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL ;

ENTITY HALF_SUB IS

PORT(A,B:IN STD_LOGIC ; DIFF,BORROW:OUT STD_LOGIC);

END HALF_SUB;

ARCHITECTURE ARCH_HALF_SUB OF HALF_SUB IS

BEGIN

DIFF <= A XOR B;

BORROW <= (NOT A) AND B;

END ARCH_HALF_SUB

Simulation waveform:

2) Full subtractor:

Circuit:

Truth table:

ABCDIFFERENCEBORROW
00000
00111
01011
01101
10010
10100
11000
11111

Code:

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL ;

ENTITY FULL_SUB IS

PORT(A,B,C:IN STD_LOGIC ; DIFF,BORROW:OUT STD_LOGIC);

END FULL_SUB;

ARCHITECTURE ARCH_FULL_SUB OF FULL_SUB IS

BEGIN

DIFF <= A XOR B XOR C;

BORROW <= ((NOT A) AND B) OR ((NOT A) AND C) OR (B AND C); 

END ARCH_FULL_SUB;

Simulation waveform:

/*54745756836*/

Leave a Comment