标签:std info tar 时间 个数 push class abc 编程
原始C语言:
#include<stdio.h> void main(){ char str[1024]; char pipei[] = "abcdefghijklmnopqrstuvwxyz"; int count[26]={0}; int i=0,j=0; scanf("%s",str); printf("%s\n",str); for(i=0;i<1024;i++) { for(j=0;j<26;j++) { if(str[i]==pipei[j]) count[j]+=1; } } for(j=0;j<26;j++) { if(count[j]>0) printf("%c=%d\n",pipei[j],count[j]); } }
加入汇编后代码:
#include<stdio.h> void main(){ char str[1024]; char pipei[] = "abcdefghijklmnopqrstuvwxyz"; int count[26]={0}; int i=0,j=0; scanf("%s",str); printf("%s\n",str); //外层循环start _asm{ mov eax,0 //i=0 mov ecx,1024 //i<1024 loop1: mov i,eax push eax push ecx }; //printf("%c\t",str[i]); //内层循环start _asm{ mov eax,0 mov ecx,26 loop2: mov j,eax push eax push ecx }; if(str[i]==pipei[j]) { count[j]+=1; } //内循环end __asm{ pop ecx pop eax add eax,1 loop loop2 }; //外循环end _asm{ pop ecx pop eax add eax,1 loop loop1 }; //输出统计个数 //外层循环start _asm{ mov eax,0 //i=0 mov ecx,26 //i<26 loop3: mov j,eax push eax push ecx }; if(count[j]>0) printf("%c=%d\n",pipei[j],count[j]); //外循环end _asm{ pop ecx pop eax add eax,1 loop loop3 }; }
后面有时间再优化了。。。。
优化如下:
#include<stdio.h> void main(){ char str[1024]; char temp; char pipei[] = "abcdefghijklmnopqrstuvwxyz"; int count[26]={0}; int i=0,j=0; char *str1 = "i=%d\n"; char *str2 = "%c\t"; scanf("%s",str); printf("%s\n",str); //temp = str[0]; printf(str2,str[i]); //汇编代码如下 //mov edx, dword ptr [ebp-48C] edx=0 //movsx eax, byte ptr [ebp+edx-400] eax=64h //push eax //mov ecx, dword ptr [ebp-498] //str2 //push ecx ; "%c" //call printf ; \printf //add esp, 8 // == //mov edx, i //movsx eax,str[edx] //push eax //mov ecx,str2 //push ecx //call printf //add esp,8 _asm{ mov i,0 start_1024: nop mov eax,i add eax,1 mov i,eax cmp i,10 // if i<10 jge end_1024 //逐个输出 printf(str2,str[i]); mov edx, i movsx eax,str[edx] push eax mov ecx,str2 push ecx call printf add esp,8 jmp start_1024 end_1024: nop } }
标签:std info tar 时间 个数 push class abc 编程
原文地址:https://www.cnblogs.com/little-kwy/p/12254025.html