You are on page 1of 2

module jhjhk(z,y,x);

input [3:0]x;
input signed[3:0]y;
reg[3:0]y1;
integer i=0;
reg e=0;
reg [1:0]a; //flag
output reg signed[7:0]z=8'd0;
//2's complement

//initial begin

always @(x,y)

begin
y1 =-y;
for(i=0;i<4;i=i+1)
begin
a={x[i],e}; //concatenate
// y1=-y;
case(a)
2'b10:z[7:4]=z[7:4]+y1;
2'b01:z[7:4]=z[7:4]+y;

default:begin
end
endcase
z=z>>>1;
e=x[i];

// end
end
end
endmodule

testbench

module jhjhk(z,y,x);
input [3:0]x;
input signed[3:0]y;
reg[3:0]y1;
integer i=0;
reg e=0;
reg [1:0]a; //flag
output reg signed[7:0]z=8'd0;
//2's complement

//initial begin

always @(x,y)

begin
y1 =-y;
for(i=0;i<4;i=i+1)
begin
a={x[i],e}; //concatenate
// y1=-y;
case(a)
2'b10:z[7:4]=z[7:4]+y1;
2'b01:z[7:4]=z[7:4]+y;

default:begin
end
endcase
z=z>>>1;
e=x[i];

// end
end
end
endmodule

You might also like