原始C语言:
#include
void main(){
char str[];
char pipei[] = "abcdefghijklmnopqrstuvwxyz";
int count[]={};
int i=,j=;
scanf("%s",str);
printf("%s\n",str);
for(i=;i
{
for(j=;j
{
if(str[i]==pipei[j])
count[j]+=;
}
}
for(j=;j
{
if(count[j]>)
printf("%c=%d\n",pipei[j],count[j]);
}
}
加入汇编后代码:
#include
void main(){
char str[];
char pipei[] = "abcdefghijklmnopqrstuvwxyz";
int count[]={};
int i=,j=;
scanf("%s",str);
printf("%s\n",str);
//外层循环start
_asm{
mov eax, //i=0
mov ecx, //i<1024
loop1:
mov i,eax
push eax
push ecx
};
//printf("%c\t",str[i]);
//内层循环start
_asm{
mov eax,
mov ecx,
loop2:
mov j,eax
push eax
push ecx
};
if(str[i]==pipei[j])
{
count[j]+=;
}
//内循环end
__asm{
pop ecx
pop eax
add eax,
loop loop2
};
//外循环end
_asm{
pop ecx
pop eax
add eax,
loop loop1
};
//输出统计个数
//外层循环start
_asm{
mov eax, //i=0
mov ecx, //i<26
loop3:
mov j,eax
push eax
push ecx
};
if(count[j]>)
printf("%c=%d\n",pipei[j],count[j]);
//外循环end
_asm{
pop ecx
pop eax
add eax,
loop loop3
};
}
后面有时间再优化了。。。。
优化如下:
构造单循环:
#include
void main(){
char str[];