|
This post was updated on .
I was frustrated with this as well. I figured it would be easy enough to set ng to the value of out[15] but I couldn't make this work in the simulator.
In the end I figured it out while trying a different approach: using And16(a,b,out) where b was a 16 bit constant bit mask with only the MSB bit set. In trying to make this work I stumbled across the idea that I could use commas to separate not only the inputs or outputs to a chip but also the PARTS of a single input:
And16(a=out, b[0..15]=true, out=ng); works as expected, how to set some bits false and one true?
lead to:
And16(a=out, b[0..14]=false, b[15]=true, out[15]=ng); Which unexpectedly almost works (This syntax looks like I'm trying to call And16() with a fourth parameter but that doesn't cause an error!) but of course this is redundant and still has a syntax problem with the output pin connection.
In the end all I needed to do was tack on the out[15]=ng part to a prior statement where I was dealing with the 'no' flag. Of course this simultaneously offended my compulsive nature while appealing to my efficient nature!
Seriously though, it is easy to forget you're simulating hardware and not writing software. I found my self asking 'why isn't there an assignment operator so I can just assign ng to the value of out[15]?' when I should have been asking myself 'what connection would I need to make between which out pin and the ng flag pin?'
The second question lead to the solution. The best place to set the ng flag is right after implementing the last input flag. This was very clear when I visualized this as a circuit, and less clear the more I fought the simulator's syntax.
On syntax:
I must have read through Appendix A 3 times before understanding this mention in one of the examples:
--------------
Example
CHIP Foo {
IN in[8] // 8-bit input
OUT out[8] // 8-bit output
// Foo's body (irrelevant to the example)
}
Suppose now that Foo is invoked by another chip using the part statement:
Foo(in[2..4]=v, in[6..7]=true, out[0..3]=x, out[2..6]=y)
---------------
How much clearer this would be if the example instead read:
-----------
. . .
Foo is typically invoked using the part statement:
Foo(in=v, out=x, out=y)
Suppose now that Foo is invoked by another chip using the part statement:
Foo(in[2..4]=v, in[6..7]=true, out[0..3]=x, out[2..6]=y)
The second example sets individual bits on an input pin as well as assigning two different sets of bits to two output pins.
-------------
Using something other than a comma to indicate multiple bindings would be the best fix here. Failing that, some explanation in prose would go a long way to helping the reader. Breaking the above example into two would help further. A simpler second example could focus solely on extending subscripting to deal with split inputs and outputs.
I'm overall very happy with the course but have on occasion been frustrated by the course materials. The quickest summary I could make of my concerns is: there seems to be a forced economy to the information provided, well beyond what could be justified by desire to keep the text approachable to novice students.
If the authors have any interest I'd be happy to share my specific observations.
|