riscvchiselrocket-chip

How to assign data to a register in chisel?


I initialized two registers in my accelerator like

val one = RegInit(0.U(5.W))
val two = RegInit(0.U(5.W))

If I have loaded a data to my rs1(R-type instruction) in my C test code, I wanted to assign this value to my self-defined register 'one'. I also want to multiply the value in register 'one' and register 'two' then give the result back to my 'rs1'. Is it possible to do those operations in chisel language?


Solution

  • You use the connection operator := to connect the output of one register to the input of another:

    val rs1 = RegInit(0.U(5.W))
    val one = RegInit(0.U(5.W))
    val two = RegInit(0.U(5.W))
    
    one := rs1
    rs1 := one * two
    

    Note that because registers are clocked, the value of a connection propagates to the value of the register on the next rising clock edge.