Reputation: 81
Hey so I am kinda new here and to RISC-V.
One of my exercise questions is:
Rotate right by 4 bits the value of 0x0000000000000123. The expected result is 0x3000000000000012, i.e. all hexadecimal digits move right by one position while the rightmost one moves to the front*
So far, I learned a little bit about the Logical Operations: andi, or, and xori
. In my previous exercises I learned add, addi, sub, slli, srli, srai
.
I started off with:
addi x6, 0x, 0x123
However, I am stuck here. My textbook doesn't really describe things properly so any assistance is much appreciated!
Upvotes: 5
Views: 3202
Reputation: 1168
Here's what I ended up doing:
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
Upvotes: 1