我需要一个类似于 LSL 的指令,但右边的位必须填充 1 而不是 0。类似于:
mov x0, 1
XXX x0, 3 -> here I should have 1111 in x0.
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有,没有一条指令可以做到这一点。从您的示例中,很难说您是否想要基于最低有效位(根据 LSb 的值是一或零)填充的算术右移之类的东西,还是总是用 1 而不是零填充。无论哪种方式,您都可以在 2/3 条指令中获得类似的结果:
MOV x0, #1
/* For the fill with LSb case */
RBIT x0, x0 /* reverse the bit order of the register */
ASR x0, x0, #3 /* use arithmetic right shift to do the shift, it will fill with the old LSb, now MSb */
RBIT x0, x0 /* fill bits back */
/* For the fill with 1s case */
MVN x0, x0 /* bitwise not the value of the register */
MVN x0, x0, LSL #3 /* shift the register value, filling with 0s, then invert the register again, restoring the original bits and flipping the filled 0s to 1s */
/* From the comments, it looks like OP wants the shift to come from another register and not a constant like in their post so the above needs an extra instruction */
MOV x1, #3 /* load the shift amount into a register */
MVN x0, x0
LSL x0, x0, x1 /* need a separate instruction to use a register instead of a constant as the shift amount */
MVN x0, x0
Run Code Online (Sandbox Code Playgroud)