0% found this document useful (0 votes)
30 views23 pages

Project Report Eoc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views23 pages

Project Report Eoc

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

SCHOOL OF ARTIFICIAL INTELLIGENCE

PROJECT REPORT
PROJECT A

DESIGN AND IMPLEMENT


16-BIT HACK CPU
INSTITUTIONAL COURSE-23AID102

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.

ALU (Arithmetic Logic Unit)


The ALU is responsible for performing all arithmetic and logical operations. Its
behaviour is controlled by six inputs (zx, nx, zy, ny, f, no), determining operations
such as addition, subtraction, and bitwise AND.
HDL Code for ALU:
CHIP ALU {
IN x[16], y[16], zx, nx, zy, ny, f, no;
OUT out[16], zr, ng;

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);

Mux16(a=y, b=false[16], sel=zy, out=yZeroed);


Not16(in=yZeroed, out=yNot);
Mux16(a=yZeroed, b=yNot, sel=ny, out=yFinal);

Add16(a=xFinal, b=yFinal, out=addOut);


And16(a=xFinal, b=yFinal, out=andOut);
Mux16(a=andOut, b=addOut, sel=f, out=fOut);

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]);
}

Program Counter (PC)


The PC keeps track of the address of the next instruction to execute. It can:
• Increment by 1 to fetch the next instruction.
• Load a new address for jump instructions.
• Reset to 0.

HDL Code for PC:


CHIP PC {
IN in[16], load, inc, reset;
OUT out[16];

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);

Register(in=nextOut, load=true, out=out);


}

16-bit HACK CPU


The CPU integrates the ALU, registers, and PC along with control logic for
instruction decoding and execution. The instruction memory provides the
program to be executed, and the data memory stores intermediate results.
HDL Code for CPU:
CHIP CPU {
IN inM[16], instruction[16], reset;
OUT outM[16], writeM, addressM[15], pc[16];

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);
}

Testing and Verification

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

16-BIT CARRY-SELECT ADDER WITH


VARIABLE BLOCK SIZES
(2-2-3-4-5)
INSTITUTIONAL COURSE-23AID102

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);

// AND gates and OR gate for cout


And(a=a, b=b, out=and1);
And(a=b, b=cin, out=and2);
And(a=a, b=cin, out=and3);
Or(a=and1, b=and2, out=or1);
Or(a=or1, b=and3, out=cout);
}

2. Multiplexer (1-bit Mux)


Used to select between two inputs based on the sel signal.
CHIP Mux {
IN a, b, sel; // Inputs: a, b, and selector sel
OUT out; // Output: selected value

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);

// Second Full Adder: Adds the most significant bits (MSBs)


FullAdder(a=a[1], b=b[1], cin=carry0, sum=sum[1], carry=carry);
}
3.2 Ripple Carry Adder (3 bits)
CHIP RippleCarryAdder3 {
IN a[3], b[3], cin;
OUT sum[3], 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=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);
}

4. Multiplexer (n-bit Mux)


4.1 Mux (2 bits)
CHIP Mux2 {
IN a[2], b[2], sel;
OUT out[2];

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]);
}

5. Carry Select Blocks


5.1 Carry Select Block (2 bits)
CHIP CarrySelectBlock2 {
IN a[2], b[2], cin;
OUT sum[2], cout;
PARTS:
RippleCarryAdder2(a=a, b=b, cin=false, sum=sum0, cout=carry0);
RippleCarryAdder2(a=a, b=b, cin=true, sum=sum1, cout=carry1);
Mux2(a=sum0, b=sum1, sel=cin, out=sum);
Mux(a=carry0, b=carry1, sel=cin, out=cout);
}
5.2 Carry Select Block (4 bits)
CHIP CarrySelectBlock4 {
IN a[4], b[4], cin;
OUT sum[4], cout;

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);
}

6. Carry Select Adder (16 bits)


CHIP CarrySelectAdder16 {
IN a[16], b[16], cin;
OUT sum[16], 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/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy