我正在使用 define 语句,但是当我 运行 代码时,它说变量未声明
I am using define statement, but when I run the code, it says the variable is not declared
根据 5 位操作码字段,我有 16 位指令,生成 27 位控制信号。我已将这些 27 位值定义为其相应的指令字。代码附在下面。当我 运行 这段代码时,它说 SW
未声明。
`define NOP 27'b 000000000000000000000000000
`define SSS 27'b 000000000000000000010000000
`define SSN 27'b 000000000000000000100000000
`define SM 27'b 000000000000000001000000000
`define SW 27'b000000000000000010000000000
module top_module(
input system_clk,
input [15:0] address,
output [15:0] instruction,
output [26:0] control_signal,
output reg [7:0] LoadReg
);
instruction_memory im(
.address(address),
.instruction(instruction)
);
instruction_decoder id(
.instr_in(instruction),
.cntrl_out(control_signal)
);
always@(posedge system_clk)
begin
case(control_signal)
SW: LoadReg <= instruction[7:0];
endcase
end
endmodule
当你声明一个define
宏时,你不需要使用反引号,但是当你使用宏时你需要添加反引号。变化:
SW: LoadReg <= instruction[7:0];
至:
`SW: LoadReg <= instruction[7:0];
根据 5 位操作码字段,我有 16 位指令,生成 27 位控制信号。我已将这些 27 位值定义为其相应的指令字。代码附在下面。当我 运行 这段代码时,它说 SW
未声明。
`define NOP 27'b 000000000000000000000000000
`define SSS 27'b 000000000000000000010000000
`define SSN 27'b 000000000000000000100000000
`define SM 27'b 000000000000000001000000000
`define SW 27'b000000000000000010000000000
module top_module(
input system_clk,
input [15:0] address,
output [15:0] instruction,
output [26:0] control_signal,
output reg [7:0] LoadReg
);
instruction_memory im(
.address(address),
.instruction(instruction)
);
instruction_decoder id(
.instr_in(instruction),
.cntrl_out(control_signal)
);
always@(posedge system_clk)
begin
case(control_signal)
SW: LoadReg <= instruction[7:0];
endcase
end
endmodule
当你声明一个define
宏时,你不需要使用反引号,但是当你使用宏时你需要添加反引号。变化:
SW: LoadReg <= instruction[7:0];
至:
`SW: LoadReg <= instruction[7:0];