|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
int checksum_v1(int *data)
{
char i;
int sum = 0;
for(i = 0; i < 64; i++)
{
sum += data;
}
return sum;
}
翻译成汇编:
checksum_v1:
MOV r2, r0
MOV r0, #0
MOV r1, #0
checksum_v1_loop
LDR r3, [r2, r1, LSL #2]
ADD r1, r1, #1
AND r1, r1, #0xff
CMP r1, #0x40
ADD r0, r3, r0
BCC checksum_v1_loop
MOV pc, r14
short checksum_v3(short *data)
{
unsigned int i;
short sum = 0;
for(i = 0; i < 64; i++)
{
sum = (short)(sum + data);
}
return sum;
}
翻译成汇编:
checksum_v3:
MOV r2, r0
MOV r0, #0
MOV r1, #0
checksum_v3_loop
ADD r3, r2, r1, LSL #1
LDRH r3, [r3, #0]
ADD r1, r1, #1
CMP r1, #0x40
ADD r0, r3, r0
MOV r0, r0, LSL #16
MOV r0, r0, ASR #16
BCC checksum_v3_loop
MOV pc ,r14
问题是checksum_v1中的LDR r3, [r2, r1, LSL #2]为什么是左移2位,而checksum_v3中ADD r3, r2, r1, LSL #1是左移1位?
|
|