On 6/17/06, Lourens Veen <[EMAIL PROTECTED]> wrote:
On Friday 16 June 2006 06:35, Tom Cook wrote:
> On 6/16/06, Timothy Miller <[EMAIL PROTECTED]> wrote:
> > I'm making this up as I go along, so I'm not sure if I'm skipping
> > over something or not.  Before we go further, I figure we should
> > have a short quiz.
> >
> > Explain this code in detail:
> >
> > module whatsit(a, b, d, c);
> > input [3:0] a, b;
> > input d;
> > output [3:0] c;
> > wire [3:0] e, f;
> > assign e = a & b;
> > assign f = a + b;
> > assign c = d ? e : f;
> > endmodule
>
> To shift this into C:
>
> char whatsit( char a, char b, bool d )
> {
>   if( d ) return a & b;
>   else return (a + b) & 0x0F;
> }

Coming from a C++ background I immediately associated a wire with an
rvalue and a const type, and a reg with an lvalue and a non-const type.
So, using pass-by-reference in C++:

I'd have to think about this, but I don't think this is an appropriate
metaphor.  In some ways, the reg/wire distinction is more syntactic
than semantic.

Also, the pass-by-reference idea could be a bit confusing.  Signals
don't have memory locations in the way as programs do.  They're wires
in logic, and stuff is going on in parallel.  I'm not sure how to
address that...

When studying software engineering, people draw these bubbles with
connections between them and call the bubbles procedures.  I always
hated that, because I don't think of procedures as automatons that
pass messages around (although I know that some languages are modeled
that way).  But when designing hardware, it makes perfect sense.


void whatsit(const char & a, const char & b, const bool & d, char & c) {
    c = d ? (a & b) : (a + b);
}

Assuming that we want 8-bit in- and outputs rather than 4-bit ones, but
that wasn't the point...

Ok, I see what you're doing here.  Yeah.  When you're passing
something IN, you're not making a copy (pass by value).  You're
hooking up a signal, which is more like pass-by-reference.  And the
most straightforward way to put something in the parameter list that's
an output is the way you did it.

Ok, maybe it IS a good metaphor.  :)
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)

Reply via email to