我正在编写 ARM 汇编代码,在某些时候必须将寄存器的单个位设置为 1。当然,最好通过“register-or
-bitmask”方法来完成。但是,根据 ARM 文档,汇编 ORR
命令(按位 OR)不采用立即值。换句话说,您只能将一个寄存器中的值与另一个寄存器中的值进行按位或。仔细想想,这是有道理的,因为 ARM 指令本身就是 32 位长,因此无法将 32 位掩码塞进指令中。但是,将立即值写入寄存器只是为了正确使用它是低效的,因为它会产生 写后读 危险会导致 CPU 停顿。一般来说,使用掩码对寄存器进行“ORR”操作而不浪费寄存器来不断将该掩码保留在内存中的最有效方法是什么? ARM 有什么推荐吗?
I'm writing ARM assembly code that at some point has to set a single bit of a register to 1. This is best done of course via "register-or
-bitmask" method. However, according to ARM documentation, the Assembly ORR
command (bitwise OR) does not take immediate values. In other words you can only bitwise-OR a value in one register with a value in another register. When you think about it, it makes sense because ARM instructions are themselves 32-bit long, so there's no way to cram a 32-bit mask into an instruction. However, writing an immediate value to a register just to use it right a way is inefficient because it produces a read-after-write hazard which stalls the CPU. In general, what is the most efficient way to ORR
a register with a mask without wasting a register on constantly keeping that mask in memory? Does ARM recommend anything?
发布评论
评论(2)
在标准 ARM 中完全没问题。您可以在 32 位 ARM 指令中对立即值进行编码,但它们的范围是有限的。 查看此说明。
您的链接指向 Thumb 文档;您确定需要使用 Thumb 指令吗?
is perfectly fine in standard ARM. You can encode immediate values in a 32-bit ARM instruction, but their range is limited. See this explanation.
Your link points to the Thumb documentation; are you sure you need to be using Thumb instructions?
尽管 ARM(或 mips,我假设还有其他)无法容纳完整的寄存器大小的立即数,但 ARM 确实具有带有立即数的 alu 操作。而且你不限于 0x00 到 0xFF 你可以
举个例子,没问题。 0x00 到 0xFF 在 32 位中的任何位置移位,某些指令可能会给你第九位 0x000 到 0x1FF (移位到任何位置),至少我似乎记得有关该工作的一些信息(对于一个/一些指令)。您按照上面的方式对指令进行编码,汇编器会负责将立即数打包到指令中。
Although ARM (or mips, and I assume others) cannot fit a full register sized immediate, ARM does have alu operations with immediate values. And you are not limited to 0x00 to 0xFF you can
for example, no problem. 0x00 to 0xFF shifted anywhere in the 32 bits some instructions might give you a ninth bit 0x000 to 0x1FF (shifted anywhere), at least I seem to remember something about that working (for one/some instructions). You code the instruction as above and the assembler takes care of packing the immediate into the instruction for you.