lcy1991 发表于 2012-2-19 12:15:56

【求助】Verilog问题

声明输出端口后可以把输出端口定义为reg类型吗?
如何把寄存器类型引出到输出端口?
我是个菜鸟,还请各位大神们帮助解答疑惑,谢谢:)

至芯兴洪 发表于 2012-2-19 12:27:54

module reg_m(clk,rst,reg_o);
input clk;
input rst;
output reg_o;

reg reg_o;
always @(posedge clk or negedge rst)
begin
   if(!rst)
    reg_o<=4'd0;
else
   reg_o<=reg_o+1'b1;
end

endmodule

lcy1991 发表于 2012-2-19 12:53:54

回复 2# 至芯兴洪
多谢多谢:handshake

lcy1991 发表于 2012-2-19 14:50:32

回复 2# 至芯兴洪
想再问你一个问题啊,一个8位乘法器


module multiplier_8bit(opa,opb, result );
       input opa;
       input opb;
       output result;
   
       reg a,b;
       integer i;
       reg result;
       
        always@(opa or opb)
               begin
               a=opa;
               b=opb;
               result=0;
                for(i=0;i<8;i=i+1)
                       begin
                          if(a) result=result+b;
                          a=a>>1;
                          b=b<<1;
                       end
               
               end

    endmodule
测试的时候积的高8位与结果不符,能帮我检查一下错误吗

至芯兴洪 发表于 2012-2-21 19:03:43

你这样写不对吧

lcy1991 发表于 2012-2-22 20:56:50

回复 5# 至芯兴洪


    那该如何写呢?就是想用移位相加实现乘法器

w0394 发表于 2012-2-29 11:55:01

回复 4# lcy1991

   b=b<<1;
时 位数变了而你写的b的位数为8位,改一下就可以了
module mult(out,a,b);
parameter size=8;
input a,b;//二个操作数
output out;//结果
reg out,temp_a;
reg temp_b;
integer i;
always @(a,b)

begin
out=0;
temp_a=a;
temp_b=b;
for(i=0;i<size;i=i+1) //for语句,size为循环次数
begin
    if(temp_b)
    out=out+temp_a;
    temp_a=temp_a<<1;
    temp_b=temp_b>>1;
end
end
endmodule
我试过可以的
页: [1]
查看完整版本: 【求助】Verilog问题