RISC-V 中的旋转位

ami*_*eur 5 bit-manipulation riscv

嘿,我对 RISC-V 还算陌生。

我的练习题之一是:

将 0x0000000000000123 的值右移 4 位。预期结果为0x3000000000000012,即所有十六进制数字右移一位,最右边的一位移到前面*

到目前为止,我了解了一些关于逻辑运算的知识:andi, or, and xori。在我之前的练习中我学到了add, addi, sub, slli, srli, srai

我从以下开始:

addi x6, 0x, 0x123
Run Code Online (Sandbox Code Playgroud)

然而,我被困在这里了。我的教科书并没有真正正确地描述事物,所以非常感谢任何帮助!

Ell*_*nay 1

这就是我最终所做的:

addi x30, x0, 0x123
andi x29, x30, 0x00f //masking all, but the right most hexadecimal digit
slli x6, x29, 60 //shifting this digit all the way to the left (rotating)
srli x7, x30, 4 //shifting the original value 4 bits right
add x5, x6, x7 //adding the two regs
Run Code Online (Sandbox Code Playgroud)

  • 使用“andi x29,x30,0x00f”进行掩码是多余的,因为无论如何,您都将这些位从下一行的寄存器中移出。 (3认同)