This is the code for byte selector
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
}
This only selects the byte 20 to 24 i.e. when i = 20 and not the rest of the bytes. Everytime I get the output as 27 which is when the for loop selects the most significant 5 bits. Can somebody help?
whenbut that will make the code too long. Is it possible to shorten it with theforloop? - Rahul