verilog quartus function 函数例子

转载:计算机人网

http://www.computersren.com/material/MaterialDetails.aspx?id=20140317222345&id2=2014030320451027176

内容:

verilog 的function 例子

code_83top.v

module code_83top(din,dout);
input[7:0] din;
output[2:0] dout;
//程序文本
function[2:0] code;      //函数定义
  input[7:0] din;      //函数只有输入,输出为函数名本身
  casex(din)
  8'b1xxx_xxxx : code = 3'h7;
  8'b01xx_xxxx : code= 3'h6;
  8'b001x_xxxx : code= 3'h5;
  8'b0001_xxxx : code= 3'h4;
  8'b0000_1xxx : code= 3'h3;
  8'b0000_01xx : code= 3'h2;
  8'b0000_001x : code= 3'h1;
  8'b0000_000x : code= 3'h0;
  default: code= 3'hx;
  endcase
endfunction
assign dout = code(din) ;      //函数调用
endmodule

code_83.v

`timescale 1ns/1ns
`include "code_83top.v"
module code_83;
reg[7:0] din;
wire[2:0] dout;
initial 
  begin //?????? 
    din=8'b1xxx_xxxx;
  end
code_83top mycount(din,dout); //??????
initial
 $monitor($time,,,"dout=%d",dout);

endmodule

第一个.v的模块可以看作是module,另一个可以测试模块。测试结果为dout=7


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值