我对 Verilog 编程完全陌生,我不明白在哪里初始化reg变量?
让我们看一下以下片段: 编辑: 合成时发出警告
module test (
output LED0
);
reg led = 1'b1;
assign LED0 = led;
endmodule
Run Code Online (Sandbox Code Playgroud)
或者
module test (
output LED0
);
reg led;
initial begin
reg led <= 1'b1;
end
assign LED0 = led;
endmodule
Run Code Online (Sandbox Code Playgroud)
给我:使用 led 的初始值,因为它从未在行中分配: reg led = 1'b1;
reg类型是否仅在 always@ 块中分配?
另一个例子:
module fourBitCounter
(input clk,
output [3:0]counter
);
wire clk;
initial begin
reg[3:0] counter = 4'b1;
end
always@ (posedge clk) begin
if(counter > 15)
counter …Run Code Online (Sandbox Code Playgroud) 我想知道为什么在调用函数时不会重新创建局部变量?
#include <iostream>
using namespace std;
void func(void)
{
int a = 0;
cout << &a << endl;
}
int main(void)
{
func();
func();
func();
func();
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么变量a每次都映射到同一个内存地址?