# 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 or s or s or cin)
begin
c=cin;
for (k=0;k<n;k=k+1)
begin
x[k]=a[k]|(s&~s&(b[k]^s));
y[k]=(s&b[k])|(s&(~b[k]));
z[k]=(~s)&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;
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 Status
Not open for further replies.