如何在verilog中将寄存器分配给输出?

如何在verilog中将寄存器分配给输出?,verilog,Verilog,我很难弄清楚如何将temp的值分配给out。我在网上搜索答案,尝试了各种方法,但仍然无法获得指定的输出。代码如下: module Reg8bit( input CLK, input En, input CLR, input [7:0] in, output [7:0] out ); reg[7:0] temp; always @(posedge CLK) begin if (En) beg

我很难弄清楚如何将temp的值分配给out。我在网上搜索答案,尝试了各种方法,但仍然无法获得指定的输出。代码如下:

module Reg8bit(
    input CLK,
    input En,
    input CLR,
    input [7:0] in,
    output [7:0] out
    );

    reg[7:0] temp;

    always @(posedge CLK)
    begin
        if (En)
        begin
            if (CLR)
                out = 8'b0000_0000;
            else
                out = in;
        end
    end

    assign out = tempQ;

endmodule

编辑:temp应该是tempQ,很抱歉输入错误

您的代码没有多大意义。您分配给out两次,但未使用临时寄存器


你可能想写这样的东西:

reg[7:0] temp;

always @(posedge CLK)
begin
    if (En)
    begin
        if (CLR)
            temp <= 0;
        else
            temp <= in;
    end
end

assign out = temp;
reg[7:0]温度;
始终@(posedge CLK)
开始
如果(英文)
开始
如果(CLR)

temp您的代码没有多大意义。您分配给out两次,但未使用临时寄存器


你可能想写这样的东西:

reg[7:0] temp;

always @(posedge CLK)
begin
    if (En)
    begin
        if (CLR)
            temp <= 0;
        else
            temp <= in;
    end
end

assign out = temp;
reg[7:0]温度;
始终@(posedge CLK)
开始
如果(英文)
开始
如果(CLR)

temp你可能是想写

module Reg8bit(
    input CLK,
    input En,
    input CLR,
    input [7:0] in,
    output reg [7:0] out // out is a variable, not a wire
    );

    always @(posedge CLK)
    begin
        if (En)
        begin
            if (CLR)
                out <= 8'b0000_0000; // use Non-blocking assignments
            else
                out <= in;
        end
    end
endmodule
模块Reg8bit(
输入时钟,
输入En,
输入CLR,
在中输入[7:0],
output reg[7:0]out//out是一个变量,而不是导线
);
始终@(posedge CLK)
开始
如果(英文)
开始
如果(CLR)

out你可能是想写

module Reg8bit(
    input CLK,
    input En,
    input CLR,
    input [7:0] in,
    output reg [7:0] out // out is a variable, not a wire
    );

    always @(posedge CLK)
    begin
        if (En)
        begin
            if (CLR)
                out <= 8'b0000_0000; // use Non-blocking assignments
            else
                out <= in;
        end
    end
endmodule
模块Reg8bit(
输入时钟,
输入En,
输入CLR,
在中输入[7:0],
output reg[7:0]out//out是一个变量,而不是导线
);
始终@(posedge CLK)
开始
如果(英文)
开始
如果(CLR)

outassign语句的LHS应该始终是一条导线。您已经声明为reg,最好在always块内的LHS中使用reg数据类型

assign语句的LHS应该始终是一条连线。您已经声明为reg,最好在always块内的LHS中使用reg数据类型

什么是tempQ?您只声明了一个名为temp的注册表。而且,您可能想写temp-what-tempQ?你只声明了一个名为temp的注册表。而且,你可能还想写temp也
temp也
temp Imho这是他想要实现的,但不是他想要写的;)为什么他说这是他想要实现的,但不是他想写的;)他为什么要出去