【发布时间】:2017-11-13 14:41:25
【问题描述】:
我正在 VIsUAL 仿真器中分析以下 ARM 程序集,这是一个循环遍历常量数组并选择最大数字的简单函数。
mov r0, r13 ; pass the memory address where you stored the array's contents
mov r1, #20 ; pass the second argument count to the function
mov r5, #04
mov r6, #01
mov r7, #13
mov r8, #42
mov r9, #25
stmfa r13, {r5,r6,r7,r8,r9}
bl max
end
max
mov r2, #0
L2
cmp r2, r1
bge L5
ldr r12, [r0, r2, lsl #2]
add r2, r2, #1
cmp r3, r12
movlt r3, r12
b L2
L5
mov r0, r3
它按预期工作,但我不明白的一件事是:
ldr r12, [r0, r2, lsl #2]
它正在将数组的当前值加载到r12中,它的开始是由当前索引r2中的r0指向的,但是为什么那里有一个左逻辑移位?
【问题讨论】:
-
因为word是4字节,所以需要缩放4,正好是左移2。