First Kind
#include <windows.h>#include<stdio.h>voidMainvoid){ intm =0, cout =0; Charcstr2find[1024x768] = {0}; printf ("Please enter a string"); scanf ("%s", Cstr2find); __asm{Pushad; //Save All registersLea Esi,cstr2find;//esi points to find stringXOR ecx,ecx;//ecx Qing 0_LOOP:LODSB; //loop to get the string lengthor Al,al; JZ _end; Inc ECX; JMP _loop;_end:mov ebx,ecx; //save string length to ebxInc ECX; Lea ESI,CSTR2FIND;_LOOP1:LODSB; //Loop to find the first character that is not a character ' 0 'Dec ecx;//ECX is used to determine if a string is foundor ECX,ECX; JZ _end2; CMP al,'0'; Je _loop1; //not the character ' 0 ' just jump up.Sub ebx,ecx;//is the character ' 0 ', you get the number of characters we compare .MOV cout,ebx;//which is where the non-' 0 ' characterjmp _end3;_end2:mov cout,-1; _end3:popad; } printf ("not 0 Location:%d\n", cout);}
The second type:
#include <windows.h>#include<stdio.h>voidMainvoid){ intm =0, cout =0; Charcstr2find[1024x768] = {0}; printf ("Please enter a string"); scanf ("%s", Cstr2find); __asm{Pushad; //Save All registersLea Edi,cstr2find; mov ecx,-1; XOR Eax,eax; Repne SCAsbyteptr Es:[edi]; not ecx; Dec ecx; //This heap of instructions is to calculate the length of a stringmov ebx,ecx; //EBX is a string lengthLea Edi,cstr2find; mov eax,0x30; Repe SCAsbytePTR Es:[edi];//Scan the first non-0 charactersor ECX,ECX;//Do you know how to play a scan?Je _panduan;//jump When you're done scanning .Sub ebx,ecx;//no scan completed with non-0 charactersDec ebx; MOV cout,ebx; //give the position to cout .jmp _end;_panduan://Note that if the last character is 0, it will also jump hereDec EDI; CMPbytePtr[edi],'0';//determine if the last character is a character 0Je _allarezero;//yes, just jump .Dec ebx; MOV cout,ebx; //The last character is a non-0jmp _end;_allarezero:mov cout,-1; _end:popad; } printf ("not 0 Location:%d\n", cout);}
The third type:
#include <windows.h>#include<stdio.h>voidMainvoid){ intm =0, cout =0; Charcstr2find[1024x768] = {0}; printf ("Please enter a string"); scanf ("%s", Cstr2find); __asm{Pushad; //Save All registersLea Esi,cstr2find;//esi points to find stringLea Edi,cstr2find; mov ecx,-1; XOR Eax,eax; Repne SCAsbyteptr Es:[edi]; not ecx; Dec ecx; //This is a bunch of instructions to find the string lengthmov ebx,ecx_loop:cmpbytePtr[esi],'0'; Jne OK; Inc ESI; Loop _loop; //Cycle ComparisonMOV cout,-1;//didn't findjmp _end; Ok:sub ebx,ecx; //found the//Dec ebx;mov cout,ebx;_end:popad; } printf ("not 0 Location:%d\n", cout);}
The fourth type:
#include <windows.h>#include<stdio.h>voidMainvoid){ intm =0, cout =0; Charcstr2find[1024x768] = {0}; printf ("Please enter a string"); scanf ("%s", Cstr2find); __asm{Pushad; //Save All registersLea Edi,cstr2find; mov ecx,-1; XOR Eax,eax; Repne SCAsbyteptr Es:[edi]; not ecx; Dec ecx; //This heap of instructions is to calculate the length of a stringmov ebx,ecx; //EBX is a string lengthLea Esi,cstr2find;_loop:mov al,'0'; Xor Al,bytePtr[esi]; or Al,al; Jne _OK; Inc ESI; Loop _loop; //Loop comparison is not the character 0jmp _allarezero_ok:sub ebx,ecx; MOV cout,ebx; JMP _end;_allarezero:mov cout,-1; _end:popad; } printf ("not 0 Location:%d\n", cout);}
The fifth type:
#include <windows.h>#include<stdio.h>voidMainvoid){ intm =0, cout =0; Charcstr2find[1024x768] = {0}; printf ("Please enter a string"); scanf ("%s", Cstr2find); __asm{Pushad; //Save All registersLea Edi,cstr2find; mov ecx,-1; XOR Eax,eax; Repne SCAsbyteptr Es:[edi]; not ecx; Dec ecx; //This heap of instructions is to calculate the length of a stringmov ebx,ecx; //EBX is a string lengthLea Esi,cstr2find;_loop:mov al,'0'; Sub Al,bytePtr[esi];//Subor Al,al; Jne _OK; //judge whether it is 0;Inc ESI; Dec ecx; //have you finished judging the comparison ?CMP ecx,0; Je _allarezero; //Jump after the contrast .jmp _loop;_ok:sub ebx,ecx; MOV cout,ebx; JMP _end;_allarezero:mov cout,-1; _end:popad; } printf ("not 0 Location:%d\n", cout);}
Compilation--Find five methods of the first non-0 characters