Minimum instructions for the ALU

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

Minimum instructions for the ALU

Saroupille
Hi,

I have 17 instructions for my implementation of the ALU. I wonder if it is possible to do it in less than 17 lines.

Regards,

Saroupille
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

cadet1620
Administrator
Saroupille wrote
I have 17 instructions for my implementation of the ALU. I wonder if it is possible to do it in less than 17 lines.
Yes, the ALU can be done with fewer parts. If you e-mail me your ALU.hdl, I will be happy to give you some pointers on how to improve it.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

n00b2Tetris
I did mine in 15;)



But I ended up using 6 Mux16's... could those be trimmed down?
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

cadet1620
Administrator
15 parts, including 6 Mux16's, is the most common way to implement the ALU.

Although it can be interesting to do, minimizing number of n2t parts in an HDL file is not necessarily a good thing.

One thing that you can do is to replace the 4 Mux16's that handle zero/invert with 2 Mux4Way16's.
This would probably be a reduction of underlying circuitry as well, depending on how Mux4Way's are implemented.

On the other hand, the 4 parts you are (probably) using to compute the 'zr' status, can be replaced by an Add16 and a Mux.  This is clearly not an improvement given the complexity of the Add16!  

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

James World
In reply to this post by Saroupille
Yes, I got it to 13, using a couple of Mux4Way16s and keeping to the 4 part zr bit construction.

James.
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

GalenaAlysonCanada
In reply to this post by cadet1620
I must be an oddball... 17 parts statements but used only one mux... I'd have to count up the nand gates to see which is actually a more minimal implementation.

I did have to invent a one-to-many fan-out part, as I see no (allowed) way to wire up a signal to a bus input, and there is no trace (wire) primitive, which seems a bit odd....(pun intended :-P )

'Lena
Reply | Threaded
Open this post in threaded view
|

Re: Minimum instructions for the ALU

cadet1620
Administrator
GalenaAlysonCanada wrote
I did have to invent a one-to-many fan-out part, as I see no (allowed) way to wire up a signal to a bus input, and there is no trace (wire) primitive, which seems a bit odd....(pun intended :-P )
It sounds like you may have figured out that Xor can be a controlled inverter. I've been designing that way (And, Or and Xor bus wide signals with control signals) for way to many years to change...

I wrote a Bus16(in[1], out[16]) part for the first version of my ALU. I used a Mux16 to implement Bus16 because I was too lazy to type all those []s 8-(. I also wrote a Wire(in, out) for direct connections.

You can put them in your nand2tetris/tools/builtInChips directory and they'll be available for all your chips to use.

--Mark