Verilog数字系统设计教程[第4版]夏宇闻——第三部分练习五

Verilog数字系统设计教程[第4版]夏宇闻——第三部分练习五

测试仿真流程

测试仿真环境为win系统下的quartus prime + modelsim
测试仿真流程参照我之前的教程
Verilog数字系统设计教程第4版夏宇闻——第三部分练习一

模块源代码

//----------alu.v----------
`define plus	 3'd0
`define minus	 3'd1
`define band	 3'd2
`define bor		 3'd3
`define unegate 3'd4

module alu(out,opcode,a,b);
output[7:0] out;
input[2:0] opcode;
input[7:0] a,b;
reg[7:0] out;

always@(opcode or a or b)
	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

测试模块代码

//----------alu.vt----------
`timescale 1 ns/ 1 ns
module alu_vlg_tst();
reg [7:0] a;
reg [7:0] b;
reg [2:0] opcode;                              
wire [7:0]  out;

parameter times = 5;

initial
	begin
		a = {$random}%256;
		b = {$random}%256;
		opcode = 3'h0;
		repeat(times)
			begin
				#100	a = {$random}%256;
						b = {$random}%256;
						opcode = opcode + 1;
			end
		#100 $stop;
	end

alu i1 (
	.a(a),
	.b(b),
	.opcode(opcode),
	.out(out)
);
                                                  
endmodule

结果波形

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值