39-function写Rom

     module rom(addr,data); 

         input[3:0] addr; 

         output[7:0] data; 

         function[7:0] romout; 

         input[3:0] addr; 

                  case(addr) 

                  0 : romout = 0; 

                  1 : romout = 1; 

                  2 : romout = 4; 

                  3 : romout = 9; 

                  4 : romout = 16; 

                  5 : romout = 25; 

                  6 : romout = 36; 

                  7 : romout = 49; 

                  8 : romout = 64; 

                  9 : romout = 81; 

                  10 : romout = 100; 

                  11 : romout = 121; 

                  12 : romout = 144; 

                  13 : romout = 169; 

                  14 : romout = 196; 

                  15 : romout = 225; 

                  default : romout = 8'hxx; 

                  endcase 

         endfunction 

         assign data = romout(addr); 

         endmodule 

`timescale 1ns/1ns
module tb_rom();
reg [3:0] addr; 
wire[7:0] data; 
rom u1(.addr(addr),.data(data));
initial begin
addr=4'd10;
#50 addr=4'd12;

end

endmodule

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值