And16

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

And16

DK3250
To simplify test I start with And4 like this:

CHIP And16 {
    IN a[4], b[4];
    OUT out[4];

    PARTS:
    And(a=a[0], b=b[0], out=out[0]);
    And(a=a[1], b=b[1], out=out[1]);
    And(a=a[2], b=b[2], out=out[2]);
    And(a=a[3], b=b[3], out=out[3]);
   
}
It works - in the sense it compiles and run without errors.
But I'm still perplexed:
I expect the two input to be list like "1101" and "0101" - but not matter my input the simulator turns it to "1". Output also becomes a single bit.
Can someone explain?
Next question: Is this really the simplest way to specify And16? 16 lines of highly repetitive code. Can I use some kind of loop here?
Reply | Threaded
Open this post in threaded view
|

Re: And16

DK3250
Ok, found out about the input - had to turn to binary.
Stupid me.

Is a more comprehensive specification possible?
Like:
    And(a=a[i], b=b[i], out[i]=out, for i=1..15)
Reply | Threaded
Open this post in threaded view
|

Re: And16

WBahn
Administrator
Nope.

Keep in mind that this is a very simple simulator with no bells and whistles. It was written by a grad student of one of the authors. Since it's only needed for five chapters worth of work, it's not too bad to deal with its limitations.
Reply | Threaded
Open this post in threaded view
|

Re: And16

DK3250
Thank you WBahn.

As I have lately studied programming (just for fun - I'm educated otherwise) I have learned to avoid repetitive code. So, just carried this habit into this study.

Thank you, again, for your support - I appreciate very much  
Reply | Threaded
Open this post in threaded view
|

Re: And16

WBahn
Administrator
"Real" HDL languages, such as VHDL and Verilog, have lots of syntactic sugar that allow you to avoid repetition. But those languages and the simulators that support them were professionally developed over many years by significant teams of people. This simulator was developed by one or two people over the course of a semester or so. Also, there's a noticeable learning curve with other HDLs in order to get the equivalent of "Hello World" up and running, whereas with this one you know almost everything you need to know to use it within about ten minutes (there's some tricks regarding sub-busing that take a bit longer to wrap your head around).

I'm very curious to see what changes have been made to the HDL for the Second Edition of the text.
Reply | Threaded
Open this post in threaded view
|

Re: And16

WBahn
Administrator
In reply to this post by DK3250
As a useful exercise you might consider devising your own HDL and then writing a program/script to take that code and generate code for this HDL. If you were actually using this HDL for some amount of time, that would pay for itself very handsomely. In this case, there's no efficiency payoff, but you'll improve your programming skills quite a bit. Plus, there's a good chance that you will gain an appreciation for why this HDL has some of the limitations that it does.
Reply | Threaded
Open this post in threaded view
|

Re: And16

DK3250
Hi WBahn,

Actually, I just started such a project - not yet finished.

Using Python and Pygame my plan is to make a small library of basic gates that I can move to the screen. Then add connections between the gates and make input(s) on/of.
All with relevant graphics.

The idea is to simulate the function/output by animating current flow - i.e. adding a very slow clock that advance in steps even along a conductor.

I may introduce resistors and capacitors as well as they are important for timing/wait sequences.

It will be able to handle only quite simple circuits, but I like the graphical element.

I'm also currently building small computer parts on breadboards - eventually ending up in a working 8-bit computer. So far I have made an adder, a register, a clock module and some minor demo parts. Now summer is approaching so I'll probably postpone until autumn - soon it is time for sailing and gardening.

Thanks for encouraging me.