Andrew wrote
What is the syntax format for using Mux, Dmux, and their descendents in constructing other chips?
For instance, and this didn't work for me, but one thing I tried was Mux(in=in, a=sel[1], b=sel[0], out=out);
Or DMux4Way(a=a,b=b,c=c,d=d,in=sel[3],out=out);
If you haven't, you need to read the
Hardware Construction Survival Guide and
Appendix A (pdf).
You can look at the HDL file for a part to see its interface. For instance, Mux.hdl declares its interface as
CHIP Mux {
IN a, b, sel;
OUT out;
To use it you need to write
Mux(a=..., b=..., sel=..., out=...);
DMux4Way declares its interface as
CHIP DMux4Way {
IN in, sel[2];
OUT a, b, c, d;
"sel[2]" means that the sel input is a 2-bit bus. Think of an N-bit bus as a bundle of wires, not an array of bits. You need to connect sel to a 2-bit bus, or you can individually connect the two wires to individual wires using
DMux4Way(..., sel[0]=aWire, sel[1]=anotherWire,...);
Sometimes you need to connect a part of a wide bus to a narrower input. To do this write something like
DMux4Way(..., sel=wideBus[11..12], ...);
This would connect bits 11 and 12 of wideBus to bits 0 and 1 of sel.
Also, is there a way to create hdl files so I can make my own custom chips?
All you need to do is create an HDL file just like the ones you have been writing, with the name of your part and the HDL that implements it. As long as your custom HDL file is in the same directory as the part that uses it, your custom part will be used. An easy way to start a custom part is to copy an existing part that has the same interface as the part you want to make. Don't forget to change the name on the CHIP line to match the new file name.
--Mark