这个问题涉及ARM汇编语言。
我的问题是是否可以使用宏来替换 ASM 代码中的立即值来移位寄存器值,这样我就不必对数字进行硬编码。
我不确定上面的问题是否有意义,所以我将提供一个带有一些asm代码的示例:
因此,存在很少的指令,例如(https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/rorror )中的指令,其中可以使用寄存器值来旋转值如我们所愿:ARM
#define rotate(number, ptr) ({ \
asm volatile( \
"ror %[output], %[output], %1\n" \
: [output]"+r"(ptr) \ // this is the in/output
: "r"(number)); \ // this is the rotator
})
Run Code Online (Sandbox Code Playgroud)
现在,让我们看一下( https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/orrorr )中的指令。ARM
语法如下:ORR{S}{cond} Rd, Rn, Operand2
其中Operand2是一个灵活的操作数,这意味着它可以是constantor a register with optional shift(来源:https ://www.keil.com/support/man/docs/armasm/armasm_dom1361289851539.htm )
所以这样的事情会起作用:
#define orr_test(ptr) ({ \
uint64_t __result; \
asm volatile (\
"orr …Run Code Online (Sandbox Code Playgroud)