*******私信博主请加V:FPGA_GO*******
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1,FPGA_Verilog基础篇:Verilog发展进程-优快云博客
2,FPGA_Verilog基础篇:理解Verilog的四值逻辑-优快云博客
3,FPGA_Verilog基础篇:Verilog中数值的表示-优快云博客
4,FPGA_Verilog基础篇:信号声明类型-优快云博客
5,FPGA_Verilog基础篇:模块的端口声明-优快云博客
6,FPGA_Verilog基础篇:verilog语言的操作符-优快云博客
7,FPGA_Verilog基础篇:verilog基本逻辑运算-优快云博客
8,FPGA_Verilog基础篇:verilog关系操作的逻辑运算实现-优快云博客
9,FPGA_Verilog基础篇:veriolg算术运算-优快云博客
10,FPGA_Verilog基础篇:verilog移位操作-优快云博客
11,FPGA_Verilog基础篇:关系操作符简介-优快云博客
12,FPGA_Verilog基础篇:拼接运算符简介-优快云博客
13,FPGA_Verilog基础篇:verilog数值的位宽扩展规则-优快云博客
14,FPGA_Verilog基础篇:verilog移位与拼接实现-优快云博客
15,FPGA_Verilog基础篇:verilog双向inout接口表示_fpga inout端口-优快云博客
16,FPGA_Verilog基础篇:verilog之锁存器和触发器-优快云博客
17,FPGA_Verilog基础篇:verilog之for循环-优快云博客
18,FPGA_Verilog基础篇:verilog之函数用法-优快云博客
19,FPGA_Verilog基础篇:verilog之任务用法-优快云博客
20,FPGA_Verilog基础篇:verilog之任务与函数用法比较-优快云博客
21,FPGA_Verilog基础篇:verilog之宏define介绍-优快云博客
22,FPGA_Verilog基础篇:verilog之条件编译指令介绍-优快云博客
23,FPGA_Verilog基础篇:verilog之参数parameter介绍-优快云博客
24,FPGA_Verilog基础篇:verilog之本地参数localparam-优快云博客
25,FPGA_Verilog基础篇:verilog之generate生成块-优快云博客
26,FPGA_Verilog基础篇:verilog之常数规则-优快云博客
27,FPGA_Verilog基础篇:verilog中整数运算的位宽和符号规则-优快云博客
28,FPGA_Verilog基础篇:verilog中的字符串表示-优快云博客
29,FPGA_Verilog基础篇:verilog中带整数的算术表达式分析-优快云博客
30(结束篇),FPGA_Verilog基础篇:verilog中的数值运算规则总结-优快云博客
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
通常情况下,咱们在实际工程中会遇到数据位宽扩展的问题(比如一个数是4bit,需要扩展为8bit),而且该数据既可能是有符号数,也可能是无符号数,此时我们该如何扩展呢?这就需要用到拼接运算符了!
对于无符号数的扩展,当然很简单,扩展位补零即可。
对于有符号数的扩展,则需要稍微注意一下!这里有一个公式:即对于一个用n位表示的有符号数据data1,比如:
wire signed [n-1:0] data1;//有符号wire型变量
reg signed [n-1:0] data1;//有符号reg型变量
我们想要将data1扩展为m位表示的data2(m>n),data2可以表示成如下:
{ {(m-n){data1[n-1]}}, data1[n-1,0] }
我们可以举例验证一下:
假设data1是有符号的4bit位宽数据7(4’sb0111),需要扩展为8bit位宽data2,代入上述公式后,data2为8’b0000_0111,确实还是7。
假设data1是有符号的4bit位宽数据-7(4’sb1001),需要扩展为8bit位宽data2,代入上述公式后,data2为8’b1111_1001,确实还是-7。
点赞加关注博主(ID:FPGA小飞)的博文,咱们一起学习、一起进步吧~