我的代码为设计模块和测试台编译,但是当我在modelsim中模拟它时,出现此错误:“加载设计时出错。 任何人都可以告诉我我的代码中哪里出错了吗?模拟verilog modelsim
下面是设计模块::
module alu(c,carry,zero,a,b,cin,opr);
input [3:0] a,b; // port A,B
input cin ; // carry input from carry flag register
output [3:0] c; // the result
output carry; // carry output
output zero ; // zero output
input [3:0] opr ; // functionality control for ALU
wire [4:0] result; // ALU result
assign result = alu_out(a,b,cin,opr);
assign c = result[3:0];
assign carry = result[4] ;
function [4:0] alu_out;
input [3:0] a,b ;
input cin ;
input [3:0] opr ;
case (opr)
4'b0001: alu_out=a+4'b0001 ; // increment data on port A
4'b0010: alu_out=a-4'b0001 ; // decrement data on port A
4'b0011: alu_out=a+b+cin; // ADD with CARRY
4'b0100: alu_out=a-b ; // SUB without BORROW
4'b0101: alu_out=a-b+(~cin); // SUB with BORROW
4'b0110: alu_out=a*b;
4'b0111: alu_out=a/b;
4'b1000: AND(alu_out, a, b);
4'b1001: OR(alu_out, a, b);
4'b1010: NAND(alu_out, a, b); // NAND
4'b1011: NOR(alu_out, a, b);
4'b1100: XNOR(alu_out, a, b);
4'b1101: alu_out=a^b; // EXOR
4'b1110: alu_out={b[3:0],1'b0}; // Shift Left
4'b1111: alu_out={b[0],1'b0,b[3:1]}; // Shift Right
default : begin
alu_out=9'bxxxxxxxxx;
$display("Invalid Operation!");
end
endcase
endfunction
endmodule
的代码,这里是测试平台的代码块:
module tb_alu();
reg [3:0] _a, _b, _opr;
reg _cin;
wire [3:0] _carry, _zero, _c;
initial begin
_a=4'b0001;
_b=4'b0010;
_cin=0;
_opr=4'b0001;
end
alu al(_c, _carry, _zero,_a, _b, _cin, _opr);
endmodule
你会得到什么输出?它与你期望的有什么不同? – toolic
为什么您的信号名称以下划线开头?那对我来说看起来很奇怪...... – Russell
得分不成问题 – user3197818