Xilinx VIvado学习-01 数值处理之乘法(无符号)

Verilog 数值处理,在处理减法的时候,需要注意溢出问题。

实例:a*b=c

 

复制代码
 1 `timescale 1ns / 1ps
 2 //////////////////////////////////////////////////////////////////////////////////
 3 // Company: 
 4 // Engineer: 
 5 // 
 6 // Create Date: 2023/10/23 23:33:07
 7 // Design Name: 
 8 // Module Name: signed_product
 9 // Project Name: 
10 // Target Devices: 
11 // Tool Versions: 
12 // Description: 
13 // 
14 // Dependencies: 
15 // 
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 // 
20 //////////////////////////////////////////////////////////////////////////////////
21 
22 
23 module unsigned_product(
24 input unsigned [7:0] a,
25 input unsigned [7:0] b,
26 output [15:0]  product
27     );
28     assign product=a*b;
29 endmodule
复制代码

仿真代码:

复制代码
 1 `timescale 1ns / 1ps
 2 //////////////////////////////////////////////////////////////////////////////////
 3 // Company:
 4 // Engineer:
 5 //
 6 // Create Date: 2023/10/26 23:46:25
 7 // Design Name:
 8 // Module Name: un_product
 9 // Project Name:
10 // Target Devices:
11 // Tool Versions:
12 // Description:
13 //
14 // Dependencies:
15 //
16 // Revision:
17 // Revision 0.01 - File Created
18 // Additional Comments:
19 //
20 //////////////////////////////////////////////////////////////////////////////////
21 
22 
23 module un_product;
24 reg sys_clk;
25 reg unsigned [7:0] a;
26 reg unsigned [7:0] b;
27 wire unsigned [15:0] c;
28 
29 initial sys_clk =1;
30 always #1 sys_clk = ~sys_clk;
31 //a = 8'h7f;
32 //b = 8'h2;
33 
34 unsigned_product u_product(
35 .a (a),
36 .b (b),
37 .product(c)
38 );
39 initial begin
40 a=0;b=0;
41 #2
42 a=49;b=73;
43 
44 #2
45 a=116;b=108;
46 #2
47 a=61;b=108;
48 #2
49 a=63;b=125;
50 end
51 //assign c = a*b;
52 
53 endmodule
复制代码

 

Vivado仿真结果如下:

 

 两个N位相乘 积用N*2+1位来表示。

posted @   古月照今尘  阅读(113)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示