【FPGA】【Verilog】【基础模块】两个数的运算 AND 一个数的运算

这篇博客主要介绍了在FPGA设计中使用Verilog语言实现数字运算的基础模块,包括两个数的AND运算以及一个数的运算。通过详细的Testbench验证,展示了加法器和半加器、全加器的设计与仿真时序,其中加法器的结果得到了验证。此外,还探讨了使用function实现阶乘的功能。
摘要由CSDN通过智能技术生成
比较器:
使用()?():()实现:
module compare(equal, a ,b);
input a ,b;
output equal;
assign equal  =  ( a == b )? 1: 0 ;
endmodule 

    Testbench:

`timescale 1 ns /100 ps 
//`include "./compare.v"

module comparetest;
reg a,b;
wire equal;
initial 
		begin
			a = 0;
			b = 0;
	#100 a = 0; b = 0;
	#100 a = 0; b = 1;
	#100 a = 1; b = 0;
	#100 a = 1; b = 1;
	#100 $stop;
	end
	
	
// assign statements (if any)                          
compare compare1 (
// port map - connection between master ports and signals/registers   
	.a(a),
	.b(b),
	.equal(equal)
);
                                        
endmodule

多功能运算:

`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;
	reg[7:0] 		out;
	input [2:0] 	opcode;
	input [7:0]		a,b;
	
	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; 
			`
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值