Pages

                           
Showing posts with label Project: Nand To Tetris in 12 Steps.... Show all posts
Showing posts with label Project: Nand To Tetris in 12 Steps.... Show all posts

Tuesday, January 4, 2011

Multiplication In Hack Assembly Language

This is a HACK Assembly language program to multiply two numbers. The numbers reside in the memory location of Register R0 and R1. This numbers are fetched and manipulated and the result is obtained.
This project is to be done in chapter 4 of the book "Elements Of Computing System". 

The assembly code for Multiplication of two numbers is as shown below:

@i
M=1
(LOOP)
@i
D=M
@R1
D=D-M
@END
D;JGT
@R0
D=M
@mul
M=M+D
@i
M=M+1
@LOOP
0;JMP
(END)
@END
0;JMP

HACK ALU

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

Monday, January 3, 2011

AND using NAND only

Implementation of AND gate using NAND gate only.
This is the first Project of  the chapter 1.

CHIP And
{
        IN a, b;
OUT out;  

PARTS:
Nand(a=a,b=b,out=x);
Not(in=x,out=out);

}

The above is the Hardware Description Language used to implement AND gate.

Monday, December 20, 2010

Project: Nand To Tetris in 12 Steps...




Cover Page of the book "The Elements of Computing Systems"



From the name of the project one will find difficult at once to know the concept behind the project. But "Nand To Tetris in 12 Steps" is the apt name that can be given to the project. This project is  the implementation of the book "The Elements of Computing Systems"  by Shimon ( IDB Professor of Information Technologies and founding dean of the Efi Arazi School of Computer Science) together with Noam Nisan in 2005.


The Basic criteria for a person implementing this project is mere graduation and some knowledge in basic computer science subjects. With this knowledge one can easily read and understand the concepts explained in the book and complete the project. The main idea is to build an entire computing system from the basic NAND gate. Hearing this one may wonder on how to implement the hardware components of the system. But the authors have taken this as a challenge and built a open source software suit which consists of Hardware Simulators. In this Hardware simulators using a simple Hardware Description Language one can easily build hardware components for building a entire system. In the different phases of the project, the  students will practice many Computer Science abstractions studied in typical CS courses. The main advantage using the software suit given along with the book is that , if one finds it difficult at any phase, they can skip to the next phase or can go in any order. 


The book contains 12 chapters in which each chapter concretes the complete hardware platform and a modern software hierarchy from the ground up, and thus maiking the students discover how computer systems work, and how they are built. The starting of the entire system is from a Nand gate from which we bulid the other gates(since Nand gate is a universal gate). And this is depicted in the 1st chapter. The 2nd chapter teaches on how to create the Combinatorial chips(Half Adder, Full Adder, ALU...) from the previously created logic gates. Then the following chapters thus defines the designing and building of  Sequential chips( Bit,Registers,RAM,...) ,Assembler, Virtual Machine and a compiler for a simple object based language all in an bottom up approach.  A mini-OS is also built, using the high-level language designed in the course. And in final phase a game is build above all the abstraction and the game is TETRIS...

And thus the final implementation from Nand To Tetris is developed in 12 steps...

The book, study plan along with the open source software suit is available here...