这是字节选择器的代码
class Comp extends Module {
val io = IO(new Bundle {
val in = Input(UInt(25.W))
val out = Output(UInt(25.W))
val i = Input(UInt(4.W))
val out0 = Output(UInt(5.W))
val out1 = Output(UInt(5.W))
})
val r8 = Wire(UInt(5.W))
io.out := Reverse(io.in)
for (i <- 0 to 20 by 5)
{
io.out0 := io.out (i+4, i)
when(io.out0 === 31.U) {
r8 := 0.U
}.elsewhen(io.out0 === 0.U) {
r8 := 31.U
}.elsewhen(io.out0 === 17.U) {
r8 := 14.U
}.elsewhen(io.out0 === 14.U) {
r8 := 17.U
}.otherwise {
r8 := 27.U
}
io.out1 := r8
}
这仅选择字节20 to 24
,即选择i = 20
而不选择其余字节。每次我得到的输出为27,这是当for循环选择最高5位的时候。有人可以帮忙吗?
答案 0 :(得分:2)
scala for循环类似于VHDL中的GENERATE,您必须将其视为:的多重声明。
io.out0 := io.out (4, 0)
io.out0 := io.out (8, 5)
io.out0 := io.out (14, 10)
io.out0 := io.out (18, 15)
io.out0 := io.out (24, 20)
您可以看到以下代码:
for ( i <- 0 to 20 by 5)
{
io.out(i) := io.out (i+4, i)
}
符号':='是信号之间的连接。以上代码的每一行都被视为擦除旧连接的新连接。
那么只有最后一个连接才会真正使用。
要进行所需的连接,您必须更改(我认为) io.out 的声明,并使用如下所示的索引:
$today = new DateTime();
$lastDayOfThisMonth = new DateTime('last day of this month');
$nbOfDaysRemainingThisMonth = $lastDayOfThisMonth->diff($today)->format('%a days');
echo "Remaining Days Of This Month = ";
echo $nbOfDaysRemainingThisMonth;
将io.out声明为向量(Vec())