|
I am stuck in zr and ng, I can't access the bits in out because it's output, and even if I make something like outin it says something like "cant access internal pins" please Help
CHIP ALU {
IN
x[16], y[16], // 16-bit 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) or (out = x & y)?
no; // negate the out output?
OUT
out[16], // 16-bit output
zr, // if (out == 0) equals 1, else 0
ng; // if (out < 0) equals 1, else 0
PARTS:
//if nx then x=0
Mux16(a=x , b=false , sel=zx , out=function1 );
// if nx then x=!x
Not16(in=function1 , out=notx );
Mux16(a=function1 , b=notx , sel=nx , out=function2 );
// if zx then y=0
Mux16(a=y , b=false , sel=zy , out=function3 );
// if ny then y=!y
Not16(in=function3 , out=noty );
Mux16(a=function3 , b=noty , sel=ny , out=function4 );
// if f=1 then x+y else x & y
Add16(a = function2, b =function4 , out = xplusy);
And16(a= function2 , b= function4, out=xandy );
Mux16(a=xandy , b=xplusy , sel=f , out=function5 );
// if no=1 then out!=out
Not16(in=function5 , out=notout );
Mux16(a=function5 , b=notout , sel=no , out=out );
|