- UID
- 102130
- 性别
- 男
|
最近开始学verilog,下面是一个乘法器的源代码,我想写个模拟环境,其中有always语句。请问高人这种类似的程序怎么写模拟环境环境,谁以能对下面的乘法器,给我作个例子。
odule byte_mult2 (nibble1, nibble2, byte_out, clk, reset);
input [3:0] nibble1, nibble2;
input clk, reset;
output byte_out;
reg [7:0] byte_out, stored3, stored2, stored1, stored0;
always @ (posedge clk or posedge reset)
if (reset)
begin
byte_out <= 0;
stored3 <= 0;
stored2 <= 0;
stored1 <= 0;
stored0 <= 0;
end
else
begin
// Shift nibble by padding with zeroes. MSB must be zero to make
// the size of the left-hand side match the set size of the
// right-hand side.
stored3 <= nibble1[3] ? {1'b0, nibble2[3:0], 3'b0} : 8'b0;
stored2 <= nibble1[2] ? {2'b0, nibble2[3:0], 2'b0} : 8'b0;
stored1 <= nibble1[1] ? {3'b0, nibble2[3:0], 3'b0} : 8'b0;
stored0 <= nibble1[0] ? {4'b0, nibble2[3:0]} : 8'b0;
byte_out <= stored3 + stored2 + stored1 + stored0;
end
endmodule |
|