我的代碼爲設計模塊和測試臺編譯,但是當我在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