Wednesday, March 14, 2012

The illusive ALU. next stop optimization


Activity 21:
Going to try to get the ALU working now with my custom chips and see if it works the way I want it to.
I think figuring out how to add overflow detection is very important when creating the ALU. Because when I go to create it in real hardware I will need to know when I get an overflow. I did create overflow detection in my adder but for the time being I am using the one the book made. Then if need be I will switch to mine.

This ALU does not do multiplication or division also it cannot do floating point math.

After reading the chapter I am not sure I understand what needs to happen. I first thought I would use a bunch of Mux’s but it doesn’t seem like it’s going to work out.

After working it out I figured most of it out but I still have to figure out how to check if the output is zero or negative.

My issue was the syntax of splitting up the pins. I think the book should cover this more clearly.
You can split the output pin as many times as you want when outputting but can not split the out put and use it for input if that makes since.

Here’s an example

    Mux16(a=AddAnd,b=NEgOut,sel=no,out[0..7]=out3,out[8..15]=out4,out[15]=out5,out=out);

Or8Way(in=out3,out=out1);
Or8Way(in=out4,out=out2);

But you cant
Or8Way(in=out[8..15],out=out);

This blog led me in the right direction.

With only one Mux input switched around I got it working and now to see on optimization.

This is the one that took the longest by far.

The Work Sheet


F(x,y)=(1) 0001
1010 (-6)
0001 (1)
Zx=1
0000
XXXXXX
Nx=1
1111
XXXXXX
Zy=1
XXXXXX
0000
Ny=1
XXXXXX
1111
X+y
  111
  1111
+ 1111
 11110
!out
 00001       (1)

F(x,y)=(1) 0001
1010 (-6)
0001 (1)
Zx=1
0000
XXXXXX
Nx=1
1111
XXXXXX
Zy=1
XXXXXX
0000
Ny=0
XXXXXX
0000
X+y
(f)=1
  111
  1111 (x)
+ 0000 (y)
  1111
!out(no)=0
  1111       (-1)

F(x,y)=x=0100(4)
0100 (4)
0101 (5)
Zx=0
0100
XXXXXX
Nx=0
0100
XXXXXX
Zy=1
XXXXXX
0000
Ny=1
XXXXXX
1111
X+y(f)=1
XandY(f)=0
(x)0100
(y)1111
   0100   
!out(no)=0
   0100 (4)

F(x,y)=y(0011)
1010 (-6)
0011(3)
Zx=1
0000
XXXXXX
Nx=1
1111
XXXXXX
Zy=0
XXXXXX
0011
Ny=0
XXXXXX
0011
X+y
XandY(f)=0
(x)1111
(y)0011
   0011   
!out(no)=0
   0011 (3)



Tuesday, March 13, 2012

Add/subtract UPDATE added over flow detection

Added an xor to my adder and then added code to the subtractor


//Created By Jeremy King for the hack computer
//The method of creating it cam from
//http://www.play-hookey.com/digital/binary_subtraction.html

/**
 * 16-bit adder/subtractor: a + b = out   if sub == 0
 *                          a - b = out   if sub == 1
 */

CHIP Subtract16 {
    IN a[16], b[16], sub;
    OUT out[16], OvF;

    PARTS:
//does not work
//Accordding to articals I read it should work
    /*Not16(in=b,out=NotB);
Inc16(in=NotB,out=outA);
Mux16(a=b,b=outA,sel=sub,out=outc);
    revAdd16(a=a,outc=outc,sub=sub,out=out); */

//works great
//This is what creats the subtraction
//This xor take a single bit input and a 16bit input
XOr16(a=sub,b=b,out=bout);
//This adder has a third single bit input to start the carry
//Also it now has over flow detection
    revAdd16(a=a,outc=bout,sub=sub,out=out,OvF=OvF);
}

An adder/ subtractor in hardware


Activity 19 E:
A subtractor. I found a schematic for a subtractor. I am attempting to implement it and then create a test script and compare file for the hardware simulator. Using a 16 bit adder and two other 16 bit logic gates I think I have a hardware subtractor. I have tried two approaches neither  one works. The issue was my full adder had to a few changes now it seems to work great. And since it’s not a project in the book I don’t see an issue of posting the code.

//Created By Jeremy King for the hack computer
//The method of creating it came from
//http://www.play-hookey.com/digital/binary_subtraction.html

/**
 * 16-bit adder/subtractor: a + b = out   if sub == 0
 *                          a - b = out   if sub == 1
 */

CHIP Subtract16 {
    IN a[16], b[16], sub;
    OUT out[16];

    PARTS:
       //does not work
       //Accordding to articals I read it should work
    /*Not16(in=b,out=NotB);
       Inc16(in=NotB,out=outA);
       Mux16(a=b,b=outA,sel=sub,out=outc);
    revAdd16(a=a,outc=outc,sub=sub,out=out); */
      
       //works great
       //This is what creats the subtraction
       XOr16(a=sub,b=b,out=bout);
       //This adder has a third single bit input to start the carry
    revAdd16(a=a,outc=bout,sub=sub,out=out);
}
Search Engine Submission - AddMe