VecShiftRegister.scala문제의 하위호환이다.
바로 풀었다.
다만, 참고할 점이 있었다.
// See LICENSE.txt for license details.
package problems
import chisel3.iotesters.PeekPokeTester
class VecShiftRegisterSimpleTests(c: VecShiftRegisterSimple) extends PeekPokeTester(c) {
val reg = Array.fill(4){ 0 }
for (t <- 0 until 16) {
val in = rnd.nextInt(256)
poke(c.io.in, in)
step(1)
for (i <- 3 to 1 by -1)
reg(i) = reg(i-1)
reg(0) = in
expect(c.io.out, reg(3))
}
}
// See LICENSE.txt for license details.
package problems
import chisel3._
// Problem:
//
// Implement a shift register with four 8-bit stages.
// Shift should occur on every clock.
//
class VecShiftRegisterSimple extends Module {
val io = IO(new Bundle {
val in = Input(UInt(8.W))
val out = Output(UInt(8.W))
})
val initValues = Seq.fill(4) { 0.U(8.W) }
val delays = RegInit(VecInit(initValues))
// Implement below ----------
delays(0) := io.in
for(i <- 1 until 4){
delays(i) := delays(i-1)
}
io.out := delays(3)
// Implement above ----------
}
val initValues = Seq.fill(4) { 0.U(8.W) }
val delays = RegInit(VecInit(initValues))
val delays = Reg(Vec(4, UInt(8.W)))