🔌
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
  • DMux4Way (4-way Demultiplexor) Chip
  • Implementation of DMux4Way Chip in HDL
  • Implementation of DMux4Way Chip in Java™
  1. Combinational Chips

DMux4Way Chip

Abstraction and Implementation of 4-way Demultiplexor Chip in Hardware Design Language and Java™.

PreviousMux8Way16 ChipNextDMux8Way Chip

Last updated 3 years ago

DMux4Way (4-way Demultiplexor) Chip

An 4-way Demultiplexor chip outputs the given input to certain output pin, which is specified by selector bit.

An m-way n-bit demultiplexor channels a single n-bit input into one of m possible n-bit outputs. The selection is specified by a set of k control bits, where k = (log m) to the base 2.

Chip name: DMux4Way
Inputs: in, sel[2]
Outputs: a, b, c, d
Function: If sel=00 then {a=in, b=c=d=0}
                else if sel=01 then {b=in, a=c=d=0}
                else if sel=10 then {c=in, a=b=d=0}
                else if sel=11 then {d=in, a=b=c=0}.

Implementation of DMux4Way Chip in HDL

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

CHIP DMux4Way {
    IN in, sel[2];
    OUT a, b, c, d;

    PARTS:
    DMux(in=in, sel=sel[1], a=ab, b=cd);
    DMux(in=ab, sel=sel[0], a=a, b=b);
    DMux(in=cd, sel=sel[0], a=c, b=d);
}

Implementation of DMux4Way Chip in Java™

Similar to the Implementation in HDL

package CombChips;

class DMux4Way_Gate extends DMux_Gate {
    
    protected static int[] DMux4Way(int in, int[] sel) {
        int[] arr_sel = new int[2];

        int[] temp = DMux(in, arr_sel[0]);
        int[] temp1 = DMux(temp[0], arr_sel[1]);
        int[] temp2 = DMux(temp[1], arr_sel[1]);

        int[] out = new int[4];
        System.arraycopy(temp1, 0, out, 0, temp1.length);
        System.arraycopy(temp2, 0, out, temp1.length, temp2.length);

        return out;
    }
}
Abstraction of 4-way Demultiplexor Chip - Representation and Truth Table