🔌
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
  • Dec16 (16-bit Decrementer) Chip
  • Implementation of 16-bit Decrementer Chip in HDL
  • Implementation of 16-bit Decrementer Chip in Java™
  1. Combinational Chips

Dec16 Chip

Abstraction and Implementation of 16-bit Decrementer Chip in Hardware Design Language and Java™.

Dec16 (16-bit Decrementer) Chip

16-bit Decrementer chip is a special kind of Subtractor, used to decrement a 16-bit input by 1.

Chip name: Dec16
Inputs: in[16]
Outputs: out[16]
Function: out=in-1

Implementation of 16-bit Decrementer Chip in HDL

The function in the above abstraction can help in the implementation of 16-bit Decrementer Chip.

The implementation of 16-bit Decrementer is analogous to 16-bit Incrementer.

You can use the Subtract16 Chip you've built earlier.

Remember that 1 in 4-bit binary (say) is 0001.

CHIP Dec16 {
    IN in[16];
    OUT out[16];

    PARTS:
   Subtract16(a=in, b[0]=true, out=out);
}

Implementation of 16-bit Decrementer Chip in Java™

Similar to the Implementation in HDL

package CombChips;

class Dec16_Gate extends Subtract16_Gate {
    
    protected static int[] Dec16(int[] in) {
        int[] b = new int[16];
        b[in.length-1] = 1;

        return Subtract16(in, b);
    }
}

The Most Significant Bit is dropped.

PreviousSubtract16 ChipNextArithmetic Chip

Last updated 3 years ago