From 37ded23c374e0f45de2cdaa4d3fa54fa9c9d003e Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 20 May 2020 17:39:50 +0530 Subject: [PATCH] [02] ALU is complete --- README.md | 2 +- projects/02/ALU.hdl | 53 ++++++++++++++++++++++++++++++++++++++++++++- projects/02/ALU.out | 37 +++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 projects/02/ALU.out diff --git a/README.md b/README.md index 8f992fe..1a72d2a 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,4 @@ Build order as per the website. Cost for each gate in NAND in brackets. - [x] Add16 (1 x HalfAdder, 15 x FullAdder) - [x] Inc16 (1 x Add16) - [x] ALU (nostat) -- [ ] ALU (complete) +- [x] ALU (complete) diff --git a/projects/02/ALU.hdl b/projects/02/ALU.hdl index f0850fc..6b9beb3 100644 --- a/projects/02/ALU.hdl +++ b/projects/02/ALU.hdl @@ -73,6 +73,57 @@ CHIP ALU { // flippedout = !maybeout Not16(in=maybeout, out=flippedout); + // out = (flippedout|maybeout) depending on no=0|1 - Mux16(a=maybeout, b=flippedout, sel=no, out=out); + Mux16(a=maybeout, b=flippedout, sel=no, out=out, + out[0]=outcopy0, + out[1]=outcopy1, + out[2]=outcopy2, + out[3]=outcopy3, + out[4]=outcopy4, + out[5]=outcopy5, + out[6]=outcopy6, + out[7]=outcopy7, + out[8]=outcopy8, + out[9]=outcopy9, + out[10]=outcopy10, + out[11]=outcopy11, + out[12]=outcopy12, + out[13]=outcopy13, + out[14]=outcopy14, + out[15]=outcopy15 + ); + + + // Split Out in 2 halves, do a bitwise OR on each to + // see if ANY bit in either half is set to 1 + + // outlow = 1 if any of out[0..7] is 1 + Or8Way(in[0]=outcopy0, + in[1]=outcopy1, + in[2]=outcopy2, + in[3]=outcopy3, + in[4]=outcopy4, + in[5]=outcopy5, + in[6]=outcopy6, + in[7]=outcopy7, + out=outlow); + // outhigh = 1 if any of out[8..15] is 1 + Or8Way(in[0]=outcopy8, + in[1]=outcopy9, + in[2]=outcopy10, + in[3]=outcopy11, + in[4]=outcopy12, + in[5]=outcopy13, + in[6]=outcopy14, + in[7]=outcopy15, + out=outhigh); + + // if either outlow or outhigh =1 , onz = 1 + Or(a=outlow, b=outhigh, out=onz); + + // negate onz to get zr + Not(in=onz, out=zr); + + Or(a=outcopy15, b=false, out=ng); } diff --git a/projects/02/ALU.out b/projects/02/ALU.out new file mode 100644 index 0000000..2424a73 --- /dev/null +++ b/projects/02/ALU.out @@ -0,0 +1,37 @@ +| x | y |zx |nx |zy |ny | f |no | out |zr |ng | +| 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 0 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 0 | 1 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | +| 0000000000000000 | 1111111111111111 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 1 | 1 | 1 | 0 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 1 | 1 | 0 | 0 | 1 | 0 | 1111111111111110 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000000001 | 0 | 0 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111111111 | 0 | 1 | +| 0000000000000000 | 1111111111111111 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000000 | 1 | 0 | +| 0000000000000000 | 1111111111111111 | 0 | 1 | 0 | 1 | 0 | 1 | 1111111111111111 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 1 | 1 | 1 | 0000000000000001 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 1 | 0 | 1 | 0 | 1111111111111111 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 0 | 0000000000010001 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 0 | 0000000000000011 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 0 | 1 | 1111111111101110 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 0 | 1 | 1111111111111100 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 1 | 1111111111101111 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 1 | 1111111111111101 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 0 | 1 | 1 | 1 | 1 | 1 | 0000000000010010 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 1 | 1 | 1 | 0000000000000100 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 1 | 1 | 1 | 0 | 0000000000010000 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 1 | 1 | 0 | 0 | 1 | 0 | 0000000000000010 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 1 | 0 | 0000000000010100 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 0 | 1 | 1 | 0000000000001110 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 1 | 1 | 1 | 1111111111110010 | 0 | 1 | +| 0000000000010001 | 0000000000000011 | 0 | 0 | 0 | 0 | 0 | 0 | 0000000000000001 | 0 | 0 | +| 0000000000010001 | 0000000000000011 | 0 | 1 | 0 | 1 | 0 | 1 | 0000000000010011 | 0 | 0 |