0007cc38 ldr r0, [sp, #0x8c + var_38]
0007cc3a movw r1, #0xec4f
0007cc3e movt r1, #0x4ec4
0007cc42 add r0, r5
0007cc44 smmul r1, r0, r1
计算前:r0 为 88, r1 为 1321528399
结果:27
0007cc38 ldr r0, [sp, #0x8c + var_38]
0007cc3a movw r1, #0xec4f
0007cc3e movt r1, #0x4ec4
0007cc42 add r0, r5
0007cc44 smmul r1, r0, r1
计算前:r0 为 88, r1 为 1321528399
结果:27
百思不得骑姐。。。。 mul是乘法指令,但是计算结果又不像乘法的结果。
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html
SMMUL
Signed Most significant word Multiply. This instruction has 32-bit operands and produces only the most significant 32 bits of the result.
Show/hideSyntax
SMMUL{R}{cond} {Rd}, Rn, Rm
where:
R
is an optional parameter. If R is present, the result is rounded, otherwise it is truncated.
cond
is an optional condition code.
Rd
is the destination register.
Rn, Rm
are the registers holding the operands.
Ra
is a register holding the value to be added or subtracted from.
Show/hideOperation
SMMUL multiplies the values from Rn and Rm, and stores the most significant 32 bits of the 64-bit result to Rd.
If the optional R parameter is specified, 0x80000000 is added before extracting the most significant 32 bits. This has the effect of rounding the result.
Show/hideRegister restrictions
You cannot use PC for any register.
You can use SP in ARM instructions but this is deprecated in ARMv6T2 and above. You cannot use SP in Thumb instructions.
Show/hideCondition flags
This instruction does not change the flags.
Show/hideArchitectures
This ARM instruction is available in ARMv6 and above.
This 32-bit Thumb instruction is available in ARMv6T2 and above. For the ARMv7-M architecture, it is only available in an ARMv7E-M implementation.
There is no 16-bit version of this instruction in Thumb.
Show/hideExamples
SMMULGE r6, r4, r3
SMMULR r2, r2, r2
Show/hideSee also
Reference
Condition codes.
B!!!, 但是iOS里面好像没有对应直接取最高有效位的数据的乘法运算符, 不过可以通过位运算实现 >>32
查了一下, 可以这样
Built-in Function: int __builtin_clz (unsigned int x)
Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
Built-in Function: int __builtin_clzll (unsigned long long)
Similar to __builtin_clz, except the argument type is unsigned long long.
相当于 _BitScanReverse, _BitScanReverse64
NSLog(@"%d", 64 - __builtin_clzll(0x00FFFFFF));
会输出24
学好汇编,走遍天下都不怕