Project Report Eoc
Project Report Eoc
PROJECT REPORT
PROJECT A
ELEMENTS OF COMPUTING 1
FACULTY INCHARGE
DR VIPIN VENUGOPAL
BATCH A - 17
A.R. NIRMAL CB.AI.U4AID24001
MANNAVA DAASARADHI CB.AI.U4AID24030
PRAJITH S CB.AI.U4AID24039
SAKTHI CHARUKESH S CB.AI.U4AID24049
Introduction
The HACK CPU is the central processing unit for the HACK computer system, as
outlined in the NAND2Tetris project. It processes instructions written in the
HACK machine language, combining arithmetic and logic operations with
memory and control functions. This report describes the step-by-step design
and implementation of a 16-bit HACK CPU using the NAND2Tetris HDL
framework.
Objectives
The project aims to:
• Design and implement a 16-bit HACK CPU capable of executing A-
instructions and C-instructions.
• Build modular components, such as registers, an Arithmetic Logic Unit
(ALU), and a Program Counter (PC), to streamline design and debugging.
• Test the CPU with predefined machine language programs to ensure
correctness and efficiency.
Methodology
The CPU design involves integrating various functional components: an ALU,
registers, control logic, and memory access units. Each component is
implemented in HDL and thoroughly tested before integration into the complete
CPU.
PARTS:
Mux16(a=x, b=false[16], sel=zx, out=xZeroed);
Not16(in=xZeroed, out=xNot);
Mux16(a=xZeroed, b=xNot, sel=nx, out=xFinal);
Not16(in=fOut, out=fNot);
Mux16(a=fOut, b=fNot, sel=no, out=out);
Or16Way(in=out, out=anySet);
Not(in=anySet, out=zr);
Or(a=out[15], b=false, out=ng);}
Registers
Registers store temporary data during computation. The HACK CPU uses the
following registers:
• A Register: Holds addresses or constant values.
• D Register: A general-purpose register used in computations.
HDL Code for A 16-bit Register:
CHIP Register {
IN in[16], load;
OUT out[16];
PARTS:
Bit(in=in[0], load=load, out=out[0]);
Bit(in=in[1], load=load, out=out[1]);
...
Bit(in=in[15], load=load, out=out[15]);
}
PARTS:
Inc16(in=out, out=incOut);
Mux16(a=out, b=incOut, sel=inc, out=incOrKeep);
Mux16(a=incOrKeep, b=in, sel=load, out=loadOrInc);
Mux16(a=loadOrInc, b=false[16], sel=reset, out=nextOut);
PARTS:
// Decode instruction type
Not(in=instruction[15], out=isAInstruction);
// Handle A-instructions
Mux16(a=instruction, b=aluOut, sel=isAInstruction, out=aIn);
Register(in=aIn, load=loadA, out=aOut);
// Handle C-instructions
Register(in=aluOut, load=loadD, out=dOut);
ALU(x=dOut, y=aOut, zx=..., nx=..., zy=..., ny=..., f=..., no=..., out=aluOut,
zr=aluZr, ng=aluNg);
PC(in=..., load=..., inc=..., reset=reset, out=pc);
}
The CPU was tested using the NAND2Tetris simulator with the provided CPU.tst
and CPU.cmp files. The test cases verified basic and advanced functionality, such
as arithmetic operations, jumps, and memory access. All test cases passed
successfully.
Conclusion
The 16-bit HACK CPU was successfully implemented, adhering to the HACK
architecture. The modular design ensured easy debugging and integration of
components. The CPU demonstrated its ability to execute a sequence of
instructions accurately, paving the way for further advancements in computer
design.
References
• Nisan, N., & Schocken, S. (2005). The Elements of Computing Systems:
Building a Modern Computer from First Principles. MIT Press.
• NAND2Tetris Official Website: nand2tetris.org
SCHOOL OF ARTIFICIAL INTELLIGENCE
PROJECT REPORT
PROJECT B-6
ELEMENTS OF COMPUTING 1
FACULTY INCHARGE
DR VIPIN VENUGOPAL
BATCH A - 17
A.R. NIRMAL CB.AI.U4AID24001
MANNAVA DAASARADHI CB.AI.U4AID24030
PRAJITH S CB.AI.U4AID24039
SAKTHI CHARUKESH S CB.AI.U4AID24049
1. Introduction
Carry-Select Adder (CSA) is one of the high-speed adders. The most significant
issues concerning achieving acceleration for general addition operations on
digital systems are related to carry propagation delay. In a CSA, several sum and
carry values are precomputed, using mux, to produce the final outcome for
different values of carry in, 0 and 1. This project introduces a 16-bit Carry-Select
Adder in Nand2Tetris HDL with block sizes varied from 2-2-3-4-5 bits to optimize
performance and minimize the carry delay.
2. Objectives
• Design and Build a 16-bit Carry-Select Adder: The goal is to design a 16-bit
Carry-Select Adder with block sizes of 2-2-3-4-5 bits. The design will
calculate two possible sum and carry outputs (for carry-in = 0 and 1) using
carry-select logic, and select the right one using multiplexers.
• Performance Optimization: By breaking the adder into blocks of different
sizes (2-2-3-4-5), the design aims to minimize the delay due to carry
propagation, optimizing the adder’s performance.
• Test and Verify the Design: Test the design with a set of test cases using
the Nand2Tetris simulator to ensure accuracy in computing sum and carry
values.
3. Approach
The 16-bit Carry-Select Adder is designed and implemented in the following
steps:
1. Full Adder
The Full Adder is the basic building block for addition in your project.
CHIP FullAdder {
IN a, b, cin;
OUT sum, cout;
PARTS:
// XOR gates for sum
Xor(a=a, b=b, out=xor1);
Xor(a=xor1, b=cin, out=sum);
PARTS:
// Implementation: (sel AND b) OR (NOT sel AND a)
And(a=b, b=sel, out=selAndB);
Not(in=sel, out=notSel);
And(a=a, b=notSel, out=notSelAndA);
Or(a=selAndB, b=notSelAndA, out=out);
}
3. Ripple Carry Adder
3.1 Ripple Carry Adder (2 bits)
CHIP RippleCarryAdder2 {
IN a[2], b[2], cin; // Two 2-bit input buses and a carry-in
OUT sum[2], carry; // 2-bit sum output and carry-out
PARTS:
// First Full Adder: Adds the least significant bits (LSBs)
FullAdder(a=a[0], b=b[0], cin=cin, sum=sum[0], carry=carry0);
PARTS:
FullAdder(a=a[0], b=b[0], cin=cin, sum=sum[0], cout=carry1);
FullAdder(a=a[1], b=b[1], cin=carry1, sum=sum[1], cout=carry2);
FullAdder(a=a[2], b=b[2], cin=carry2, sum=sum[2], cout=cout);
}
3.3 Ripple Carry Adder (4 bits)
CHIP RippleCarryAdder4 {
IN a[4], b[4], cin;
OUT sum[4], cout;
PARTS:
FullAdder(a=a[0], b=b[0], cin=cin, sum=sum[0], cout=carry1);
FullAdder(a=a[1], b=b[1], cin=carry1, sum=sum[1], cout=carry2);
FullAdder(a=a[2], b=b[2], cin=carry2, sum=sum[2], cout=carry3);
FullAdder(a=a[3], b=b[3], cin=carry3, sum=sum[3], cout=cout);
}
3.4 Ripple Carry Adder (5 bits)
CHIP RippleCarryAdder5 {
IN a[5], b[5], cin;
OUT sum[5], cout;
PARTS:
FullAdder(a=a[0], b=b[0], cin=cin, sum=sum[0], cout=carry1);
FullAdder(a=a[1], b=b[1], cin=carry1, sum=sum[1], cout=carry2);
FullAdder(a=a[2], b=b[2], cin=carry2, sum=sum[2], cout=carry3);
FullAdder(a=a[3], b=b[3], cin=carry3, sum=sum[3], cout=carry4);
FullAdder(a=a[4], b=b[4], cin=carry4, sum=sum[4], cout=cout);
}
PARTS:
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
}
4.2 Mux (3 bits)
hdl
Copy code
CHIP Mux3 {
IN a[3], b[3], sel;
OUT out[3];
PARTS:
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
}
4.3 Mux (4 bits)
CHIP Mux4 {
IN a[4], b[4], sel;
OUT out[4];
PARTS:
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
}
4.4 Mux (5 bits)
CHIP Mux5 {
IN a[5], b[5], sel;
OUT out[5];
PARTS:
Mux(a=a[0], b=b[0], sel=sel, out=out[0]);
Mux(a=a[1], b=b[1], sel=sel, out=out[1]);
Mux(a=a[2], b=b[2], sel=sel, out=out[2]);
Mux(a=a[3], b=b[3], sel=sel, out=out[3]);
Mux(a=a[4], b=b[4], sel=sel, out=out[4]);
}
PARTS:
RippleCarryAdder4(a=a, b=b, cin=false, sum=sum0, cout=carry0);
RippleCarryAdder4(a=a, b=b, cin=true, sum=sum1, cout=carry1);
Mux4(a=sum0, b=sum1, sel=cin, out=sum);
Mux(a=carry0, b=carry1, sel=cin, out=cout);
}
PARTS:
CarrySelectBlock2(a=a[0..1], b=b[0..1], cin=cin, sum=sum[0..1], cout=carry1);
CarrySelectBlock2(a=a[2..3], b=b[2..3], cin=carry1, sum=sum[2..3],
cout=carry2);
CarrySelectBlock3(a=a[4..6], b=b[4..6], cin=carry2, sum=sum[4..6],
cout=carry3);
CarrySelectBlock4(a=a[7..10], b=b[7..10], cin=carry3, sum=sum[7..10],
cout=carry4);
CarrySelectBlock5(a=a[11..15], b=b[11..15], cin=carry4, sum=sum[11..15],
cout=cout);
}
4. Software Tools:
• The Nand2Tetris Software Package for simulation and HDL code
compilation.
6. Testing and Results:
The design was tested using various test cases, including random binary
numbers and edge cases (e.g., all zeros, all ones, and scenarios with high carry
propagation). The simulator confirmed that the adder accurately computed the
sum and carry for all input combinations.
7. Conclusion:
This project successfully designed and implemented a 16-bit Carry-Select Adder
using Nand2Tetris HDL. The use of modular blocks (2-2-3-4-5 bits) reduced carry
propagation delay, optimizing performance. The carry-select logic coupled with
modularity provided an efficient solution.
8. References:
• Nisan, N., & Schocken, S. (2005). The Elements of Computing Systems:
Building a Modern Computer from First Principles. MIT Press.
• Nand2Tetris official website: https://www.nand2tetris.org/