'Wire' command?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

'Wire' command?

Ferg
Say I want a=b or a=b[0], a=b[1], a=b[2]... etc.

Is there a connect or wire command? I could double up not gates each time but it seems kinda wasteful.

It seems like if I have a 16 bit input and a 1 bit input I can't use the And16, Or16 chips without this.

 
Reply | Threaded
Open this post in threaded view
|

Re: 'Wire' command?

cadet1620
Administrator
If I understand correctly, you want to And a 16-bit bus with a single-bit signal. The best you can do with And16 is
    And16(a=a16, b[0]=b, b[1]=b ... b[15]=b, out=out16)
where a16 and out16 are 16-bit buses and b is a single-bit signal.

Although single-bit signals can't connect to buses, the builtin 'true' and 'false' can be connected to buses. There are clever ways to use Mux16 to convert a simple signal to a bus, and to make the 16x1 And and Or.

(I did initially write a Wire part using out=!!in, and a Make16 part that used Wire to connect the in to all the outs, before I figured out the Mux16 tricks.)

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: 'Wire' command?

Ferg
Thanks mark,

That was one of my intentions but I was speaking more generally. I was trying to avoid having to write a wire or make16 'chip' without first checking that there was not a simpler way.

Any reason why these functions do not exist? I understand the need to use of designing more complicated chips from simpler chips but making a wire from Nand gates seems a bit mad to me.

I'll look into the Mux16 approach though, thanks for the hint.

One last syntax question. Internal arrays/buses, How do I define them?

Lets say I want to do something like--

Xor(a=x[0],b=nx, out=int[0])
//where int is a 16-bit internal bus that has not been defined anywhere before...

I get an error when I try this, should I just make an Xor16 chip?  

Reply | Threaded
Open this post in threaded view
|

Re: 'Wire' command?

cadet1620
Administrator
I only found TECS last fall when I was looking for materials for an ex-student of mine, so I can only guess about motivations about what was and wasn't included. My guess it the the authors wanted to emphasize that everything can be derived from NAND (they could have used NOR instead). It makes a good primitive function because it's at the boundary between mathematical logic and physical electronics.

I raced through chapters 1-3 so that I could be ahead of my student so I did things as quickly as possible and ended up make several chips that were not in the projects so that I could build the more complex chips: Wire, Make16, And16x1, and others. Later I went back and thought about how to use only the chips in the projects to build everything. (And without using the chips in strange ways.)


Using two NANDs to make a wire isn't as insane as you think. Check out Signal Crossing.


Internal buses are created when they are connected to a part's output. You can't connect a bunch of outputs together to make an internal bus. You can hook more than one signal or bus to an output. For example

    And16(..., out=word, out[0..7]=lowByte, out[8..15]=highByte);
creates 3 internal buses: word is 16 bits wide, lowByte and highByte are 8 bits wide.

If you want an Xor that operates on 16-bit buses, build an Xor16 out of Xors. If you want to Xor a 16-bit bus with a 1-bit signal, that's another job for Mux16 with the help of another xxx16 chip that you've already built for the project.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: 'Wire' command?

Ferg
Thanks Mark, this helps a lot.