# Help Needed in Making a 2 bit ALU

Status
Not open for further replies.

#### shafin

##### Newbie level 2
I need to build a ALU with the following operations:

Transfer
Increment
Subtraction
Subtract with borrow
Decrement
OR
XOR
AND
NOT

I've got the Design from the Morris Mano book.But I need to reduce the number of gates to as small as possible.The design in the book uses 28 gates,counting the initial NOT gates.I succeeded in reducing it to 22 gates,but i've heard it has been implemented with lower number of gates.

#### deepu_s_s

##### Full Member level 5
can u post the code u used for the design!

#### shafin

##### Newbie level 2
The code is:

Code:
module alu(a,b,s,cin,f,cout,lc);
parameter n=2;
input [n-1:0]a,b;
input [2:0]s;
input cin;
output [n-1:0]f;
output cout;
inout lc;
assign lc=1;
reg [n:0]c;
reg [n-1:0]f;
reg [n-1:0]x,y,z;
reg cout;
integer k;

always @(a or b or s[2] or s[1] or s[0] or cin)
begin
c[0]=cin;
for (k=0;k<n;k=k+1)
begin
x[k]=a[k]|(s[2]&~s[0]&(b[k]^s[1]));
y[k]=(s[0]&b[k])|(s[1]&(~b[k]));
z[k]=(~s[2])&c[k];
f[k]=x[k]^y[k]^z[k];
c[k+1]=(x[k]&y[k])|(y[k]&z[k])|(z[k]&x[k]);
end
cout=c[n]&~s[2];
end
endmodule

Now I need to decrease the No of gates to lowest possible.If you need,I can post an Image of the circuit.

Thanks

#### khaila

##### Full Member level 2
Could you plz post the block diagram of the design???

#### shafin

##### Newbie level 2
Forgive me for my horrible drawing,I had drawn this in a hurry,I just hope you can still recognize it.

The pic is for one of the cascading stages of the ALU.I hope you can help me decrease the number of gates.

Status
Not open for further replies.