本文作为SpinalHDL学习笔记第五十五篇,介绍SpinalHDL的Bits数据类型。
目录:
1.描述(Description)
2.声明(Declaration)
3.操作符(Operators)
1.描述(Description)
Bits类型对应于没有算数意义的bits向量。
2.声明(Declaration)
声明bit向量的语法如下所⽰:([]中为可填项)
//Declaration
val myBits = Bits()
val myBits1 = Bits(32 bits)
val myBits2 = B(25, 8 bits)
val myBits3 = B"8'xFF" //基可以是x/h(16), d(10), o(8), b(2)
val myBits4 = B"1001_0011" //_增加可读性
//Element
val myBits5 = B(8 bits, default -> True) //"11111111"
val myBits6 = B(8 bits, (7 downto 5) -> B"101", 4 -> true, 3 -> True, default -> false)
//"10111000"
val myBits7 = Bits(8 bits)
myBits7 := (7 -> true, default -> false) //"10000000",在赋值的时候可以省去B
Verilog:
wire [7:0] myBits;
wire [31:0] myBits1;
wire [7:0] myBits2;
wire [7:0] myBits3;
wire [7:0] myBits4;
wire [7:0] myBits5;
reg [7:0] myBits6;
reg [7:0] myBits7;
assign myBits = 8'h19;
assign myBits2 = 8'h19;
assign myBits3 = 8'hff;
assign myBits4 = 8'h93;
assign myBits5 = 8'hff;
function [7:0] zz_myBits6(input dummy);
begin
zz_myBits6 = 8'h0;
zz_myBits6[7 : 5] = 3'b101;
zz_myBits6[4] = 1'b1;
zz_myBits6[3] &#