Reputation: 2042
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.
Upvotes: 4
Views: 3711
Reputation: 774
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.
Upvotes: 1
Reputation: 111
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
Upvotes: 5
Reputation: 30045
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.
Upvotes: 8