module account(tempreg,count);
input [3:0]tempreg;
output [1:0]count;
reg [1:0]count;
reg [3:0]tem;
initial
begin
// count=0;
end
always @(tempreg)
begin
tem=tempreg;
/*if(tem[0])
begin
count=count+1;
tem=tem>>1;
end*/
case(tem)
4'b0000:count=0;
4'b0001:count=1;
4'b0010:count=1;
4'b0011:count=2;
4'b0100:count=1;
4'b0101:count=2;
4'b0110:count=2;
4'b0111:count=3;
4'b1000:count=1;
4'b1001:count=2;
4'b1010:count=2;
4'b1011:count=3;
4'b1100:count=2;
4'b1101:count=3;
4'b1110:count=3;
4'b1111:count=4;
endcase
end
endmodule
给个组合逻辑的示例吧,不过中间有些小错误,逻辑性的啊,呵呵. |