我正在尝试使用Verilog语言实现ALU; 作为第一种方法,我想模拟它的这个非常简单的版本:
module alu(opcode, in1, in2, result);
input[4:0] opcode;
input[11:0] in1, in2;
output[11:0] result;
case(opcode)
5'b00000 assign result=in1+in2;
5'b00010 assign result=in1;
5'b00011 assign result=in1+1;
5'b01000 assign result=in1<<1;
5'b01001 assign result=in1>>>1;
5'b10001 assign result=in1 && in2;
5'b10010 assign result=in1 || in2;
endcase
endmodule
Run Code Online (Sandbox Code Playgroud)
不管它的简单性,我得到这个编译错误:
case(opcode)
|
*E,NOTPAR: Illegal operand for constant expression [4(IEEE)].
Run Code Online (Sandbox Code Playgroud)
我真的无法弄清楚代码有什么问题.
1)放入case组合总是阻塞(即always @ (*)如果你使用的是verilog 2001语法).
2)删除assign关键字,声明result为output reg
3)放在:条件之后,比如5'b0000:
4)注意算术运算中可能出现的溢出
5)逻辑and并or给出1位结果,然后将其分配给12位输出.也许你想要上述操作的按位版本(google的区别)?
| 归档时间: |
|
| 查看次数: |
402 次 |
| 最近记录: |