正在加载图片...
第十章.设计练习进阶 output[7: 0]out reg[7:0] input[7: 0] a, b //操作数。 always@( opcode or a or b)//电平敏感的 always块 case(opcode) a+b;//加操作 minus:out=a-b;//减操作。 band:out=a&b;//求与。 bor:out=a|b:/求或。 negate:out=a;//求反。 default:out=8'hx://未收到指令时,输出任意态。 endcase 同一组合逻辑电路分别用 always块和连续赋值语句 assign描述时,代码的形式大相径 庭,但是在 always中适当运用 default(在case结构中)和else(在if.else结构中), 通常可以综合为纯组合逻辑,尽管被赋值的变量一定要定义为reg型。不过,如果不使用 default或else对缺省项进行说明,则易生成意想不到的锁存器,这一点一定要加以注意 指令译码器的测试模块源代码: timescale Ins/Ins include "./alu module alutest e[7:0] 7:0]a,b parameter times=5 initial egin a= Random)%256; //Give a radom number blongs to [o, 255 b=Random //G opcode3 ho a=Random/%256: //Give a radom number. rando //Give a radom number 274第十章.设计练习进阶 output[7:0] out; reg[7:0] out; input[2:0] opcode; input[7:0] a,b; //操作数。 always@(opcode or a or b) //电平敏感的 always 块 begin case(opcode) `plus: out = a+b; //加操作。 `minus: out = a-b; //减操作。 `band: out = a&b; //求与。 `bor: out = a|b; //求或。 `unegate: out=~a; //求反。 default: out=8'hx;//未收到指令时,输出任意态。 endcase end endmodule 同一组合逻辑电路分别用 always 块和连续赋值语句 assign 描述时,代码的形式大相径 庭,但是在 always 中适当运用 default(在 case 结构中)和 else(在 if…else 结构中), 通常可以综合为纯组合逻辑,尽管被赋值的变量一定要定义为 reg 型。不过,如果不使用 default 或 else 对缺省项进行说明,则易生成意想不到的锁存器,这一点一定要加以注意。 指令译码器的测试模块源代码: //------------- alu_Top.v ----------------- `timescale 1ns/1ns `include "./alu.v" module alutest; wire[7:0] out; reg[7:0] a,b; reg[2:0] opcode; parameter times=5; initial begin a={$random}%256; //Give a radom number blongs to [0,255] . b={$random}%256; //Give a radom number blongs to [0,255]. opcode=3'h0; repeat(times) begin #100 a={$random}%256; //Give a radom number. b={$random}%256; //Give a radom number. opcode=opcode+1; end 274
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有