Built the ALU and tested as working.

This commit is contained in:
2021-02-12 17:00:52 -06:00
parent e0703c9f60
commit 731818ea92
2 changed files with 60 additions and 1 deletions
+23 -1
View File
@@ -42,5 +42,27 @@ CHIP ALU {
ng; // 1 if (out < 0), 0 otherwise
PARTS:
// Put you code here:
// Zero out X / Y?
Mux16(a=x, b=false, sel=zx, out=x1);
Mux16(a=y, b=false, sel=zy, out=y1);
// Handle negating the input
Not16(in=x1, out=negatedX);
Mux16(a=x1, b=negatedX, sel=nx, out=x2);
Not16(in=y1, out=negatedY);
Mux16(a=y1, b=negatedY, sel=ny, out=y2);
// 2's compliment
And16(a=x2, b=y2, out=xAndy);
Add16(a=x2, b=y2, out=xPlusy);
Mux16(a=xAndy, b=xPlusy, sel=f, out=xy);
// Negate
Not16(in=xy, out=notXY);
Mux16(a=xy, b=notXY, sel=no, out[15]=ng, out[8..15]=msb, out[0..7]=lsb, out=out);
// Is zero?
Or8Way(in=msb, out=msbResult);
Or8Way(in=lsb, out=lsbResult);
Or(a=msbResult, b=lsbResult, out=result);
Not(in=result, out=zr);
}