🔌
nand2tetris
  • Introduction
  • Combinational Chips
    • Nand Gate
    • Not Gate
    • And Gate
    • Or Gate
    • Xor Gate
    • Multiplexor Chip
    • Demultiplexor Chip
    • Not16 Chip
    • And16 Chip
    • Or16 Chip
    • Mux16 Chip
    • Or8Way Chip
    • Mux4Way16 Chip
    • Mux8Way16 Chip
    • DMux4Way Chip
    • DMux8Way Chip
    • Half Adder Chip
    • Full Adder Chip
    • Add16 Chip
    • Inc16 Chip
    • Half Subtractor Chip
    • Full Subtractor Chip
    • Subtract16 Chip
    • Dec16 Chip
    • Arithmetic Chip
    • ALU
  • Misc
    • Int2Bool
    • Bool2Int
    • Arrayto16
Powered by GitBook
On this page
  • Full Subtractor Chip
  • Implementation of Full Subtractor Chip in HDL
  • Implementation of Full Subtractor Chip in Java™
  1. Combinational Chips

Full Subtractor Chip

Abstraction and Implementation of Full Subtractor Chip in Hardware Design Language and Java™.

PreviousHalf Subtractor ChipNextSubtract16 Chip

Last updated 3 years ago

Full Subtractor Chip

Full Subtractor chip is used to subtract 3-bits.

Chip name: FullSubtractor
Inputs: a, b, c
Outputs: diff, borrow
Function: diff = LSB of a - b - c
          borrow = MSB of a - b - c
Abstraction of Full Subtractor Chip - Representation, Implementation and Truth Table

Implementation of Full Subtractor Chip in HDL

The function in the above abstraction can help in the implementation of Full Subtractor Chip.

diff = a XOR b XOR c

borrow = (a' AND b) OR (b AND c) OR (a' AND c)

CHIP FullSubtractor {
    IN a, b, c;  // 1-bit inputs
    OUT diff,     // Right bit of a + b + c
        borrow;   // Left bit of a + b + c

    PARTS:
    // Put you code here:
    HalfSubtractor(a=a, b=b, diff=diffab, borrow=borrowab);
    HalfSubtractor(a=diffab, b=c, diff=diff, borrow=temp);
    Or(a=temp, b=borrowab, out=borrow);
}

Implementation of Full Subtractor Chip in Java™

Similar to the Implementation in HDL

package CombChips;

class FullSubtractor_Gate extends HalfSubtractor_Gate {

    protected static int[] FullSubtractor(int a, int b, int c) {
        int[] out = new int[2];

        int[] ab = HalfSubtractor(a, b);
        int[] temp = HalfSubtractor(ab[0], c);
        int borrow = Or_Gate.Or(temp[1], ab[1]);

        out[0] = temp[0];
        out[1] = borrow;

        return out;
    }
}