This is the implementation of Hack Arithmetic And Logic Unit (ALU) of chapter 2. ALU is implemented by using the previously built gates of chapter 1 and chapter 2 . ALU consists of 8 inputs and 3 outputs. Depending on the value of zx, nx, zy, ny, f and no all the operations of ALU are performed on input x and y.
The HDL code for ALU is as shown below:
CHIP ALU{
IN x[16],y[16],zx,nx,zy,ny,f,no;
OUT out[16],zr,ng;
PARTS:
Mux16(a=x,b[1..15]=false,sel=zx,out=w2);
Not16(in=w2,out=w3);
Mux16(a=w2,b=w3,sel=nx,out=x1);
Mux16(a=y,b[1..15]=false,sel=zy,out=w5);
Not16(in=w5,out=w6);
Mux16(a=w5,b=w6,sel=ny,out=y1);
Add16(a=x1,b=y1,out=add1);
And16(a=x1,b=y1,out=or1);
Mux16(a=or1,b=add1,sel=f,out=out1);
Not16(in=out1,out=out2);
Mux16(a=out1,b=out2,sel=no,out=out,out=test,out[0..7]=fstout,out[8..15]=sndout);
And16(a=test,b[15]=true,b[0..14]=false,out[15]=ng);
Or8Way(in=fstout,out=orout1);
Or8Way(in=sndout,out=orout2);
Or(a=orout1,b=orout2,out=orout3);
Not(in=orout3,out=zr);
}
No comments:
Post a Comment