

For the ALU chip (just the first part), chapter 2
CHIP ALU {
IN
x, y, // 16bit inputs
zx, // zero the x input?
nx, // negate the x input?
zy, // zero the y input?
ny, // negate the y input?
f, // compute out = x + y (if 1) or x & y (if 0)
no; // negate the out output?
OUT
out, // 16bit output
zr, // 1 if (out == 0), 0 otherwise
ng; // 1 if (out < 0), 0 otherwise
PARTS:
//sorting both zx and nx
Not16(in=x,out=negx);
Mux4Way16(a=x,b=false,c=negx,d=true,sel[0]=zx,sel[1]=nx,out=outx);
//sorting both zy and ny
Not16(in=y,out=negy);
Mux4Way16(a=y,b=false,c=negy,d=true,sel[0]=zy,sel[1]=ny,out=outy);
//Anding and Adding outputs from x and y
And16(a=outx,b=outy,out=xandy);
FullAdder16(a=outx,b=outy,sum=xsumy,carry=ignore);
//selecting either x And y or x ADD y from above
Mux16(a=xandy,b=xsumy,sel=f,out=fout);
//sorting whether the output is negated or not
Not16(in=fout,out=nfout);
Mux16(a=fout,b=nfout,sel=no,out=out);
The error i'm getting is that the bus in the first and second Not Gates aren't the right size. The HardwareSimulator seems to think x is only one bit, despite it being declared as 16 bit in the chip header.
If i use x[16] the error message i get is "the specified sub bus is not in t.."
Unfortunately i can't get the full error message either resizing the window, or using HWS from the commandline; from which i get "End of script  Comparison ended successfully" ie no error message.
Is it that you've just got to implement the chip using Mux16 and you're not "allowed" to solve the problem in any other way ?
Or am i just doing something really stupid and i just can't see it ?
Thanks in advance !

Administrator

The problem is that, in your code, the inputs are NOT sixteen bits.
Look at your code and see if you could point out to someone else where the emulator is supposed to determine that the x and y inputs are 16 bits wide.
Then go back and look at the ALU.hdl file supplied by the authors and try to do the same thing.
Fix that and then let's see if there are any problems remaining.


Thanks for your help, i didn't realise that I also now needed to define the chip header as well. I put [16] next to x,y and out, and i then got a whole load of other errors ! (that were easy to resolve)
For completeness, in case anyone else finds this useful the FullAdder 16 bit is called Add16 not FullAdder16 which were my other errors.
Phew I thought my HardwareSimulator was broke, but as per, it's my error.
Again WBahn thanks for your prompt reply, nice one.
The working header:
CHIP ALU {
IN
x[16],y[16], // 16bit inputs
zx, // zero the x input?
nx, // negate the x input?
zy, // zero the y input?
ny, // negate the y input?
f, // compute out = x + y (if 1) or x & y (if 0)
no; // negate the out output?
OUT
out[16], // 16bit output
zr, // 1 if (out == 0), 0 otherwise
ng; // 1 if (out < 0), 0 otherwise
PARTS:
//sorting x, zx, nx
Not16(in=x,out=negx);
Mux4Way16(a=x,b=false,c=negx,d=true,sel[0]=zx,sel[1]=nx,out=outx);
(I haven't included the rest of the code as i didn't want to do a spoiler..)
..
..
etc
}
Lozminda

