新人提问:这小段汇编要怎么写效率才比直接用c写高啊
这一段教科书上拷下来的,自己编译发现还是c语言写的效率高些C语言:
int ii=36;
int jj=96;
while (ii != jj)
{
if (ii > jj) ii -= jj;
else jj -= ii;
}
汇编:
__asm {
mov r2, #36
mov r3, #96
loop:
cmp r2, r3
subgt r2, r2, r3
sublt r3, r3, r2
bne loop
}
还有这一段简单的字符拷贝也是c语言效率高(机器自动优化以后)
c语言:
char *a = "012345678912";
char *b = new char[64];
while ((*b++=*a++)!='\0');
汇编:
char *a = "012345678912";
char *b = new char[64];
__asm {
loop:
ldrb r0, [a], #1
strb r0, [b], #1
cmp r0, #0
bne loop
}