ARM SUB 指令操作数
我正在使用 llvm-clang 编译器,将简单的 C 函数编译为 ARMv7-A 处理器上的汇编。我想弄清楚这个指令的作用。
SUB sp, sp, #65, 30
显然,它在堆栈指针上为一些局部变量腾出了空间,但我从未见过带有四个操作数的 ARM SUB 指令。我猜测 30 以某种方式修改了 #65,但我不知道如何修改,而且我也无法在 ARM 架构参考手册中找到详细信息。有什么建议吗?
出于好奇,这是在创建 8 x 8 整数单位矩阵的程序的开头,因此我希望 sp 需要在堆栈上为至少 8 x 8 x 4 字节腾出空间。
I'm working with the llvm-clang compiler, compiling simple C functions down to assembly on an ARMv7-A processor. I am trying to figure out what this instruction does.
SUB sp, sp, #65, 30
Obviously it's making room on the stack pointer for some local variables, but I've never seen an ARM SUB instruction with four operands. I'm guessing that the 30 modifies the #65 somehow, but I don't know how, and I haven't been able to find details in the ARM Architecture Reference Manual. Any suggestions?
For the curious, this is at the beginning of a program that creates an 8 x 8 identity matrix of integers, so I would expect the sp to need to make room for at least 8 x 8 x 4 bytes on the stack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
30 是 65 上的右循环运算。
右循环 30 位与左循环 2 位相同,相当于乘以 4。 65 * 4 = 260
因此,这会从堆栈指针中减去 260。
The 30 is a rotate right operation on the 65
Rotating right 30 bits is the same as rotating left 2 bitswhich is the same as a multiply by 4. 65 * 4 = 260
So this subtracts 260 from the stack pointer.
ARM 设计为立即值分配 12 位,为值分配 8 位,剩余 4 位为右循环(表示 0 2 4 等位置的循环)。由于 260 无法用 8 位表示,因此将其构造为 65*4。
这将程序员可用的立即值分布在整个 32 位范围内,而不是将其限制为 0 到 4095
The arm design allocates 12 bits for immediate values, 8 bits for the value and the remaing 4 bits are a rotate right (represeting rotates of 0 2 4 etc. places). Since 260 cant be represented in 8 bits its constructed as 65*4.
This spreads out the immediate values available to the programmer over the whole 32bit range rather than restrict it to 0 to 4095
ARM 反汇编程序有时会以这种格式输出常量,因为 8 位常量 + 4 位 ROR 编码允许某些值以不同的方式进行编码。例如,1 可以编码为 1 ROR 0、4 ROR 2、16 ROR 4 等。
解码为这种格式允许明确指定指令编码,并允许重新组装准确的指令。构建按位相同的二进制文件可能很重要。
The ARM disassemblers sometimes spit out constants in this format as the 8-bit constant + 4-bit ROR encoding allows some values to be encoded in different ways. e.g. 1 can be encoded as 1 ROR 0, 4 ROR 2, 16 ROR 4, etc.
Decoding to this format allows the instruction encoding to be unambiguously specified and allows the exact instruction to be re-assembled. It may be important to build a bitwise identical binary.