Etichetă: asscii strlen asm

Snippet StrLen Asm

This article has been written before more than 24months, information might old.

Avem in windows functia lstrlen , dar lstrlen nu reda marimea in format numeric , asa ca trebuie transformat in ascii de prefeinta , putem face asta cu functia dwtoa care se afla in masm32.lib dar decat sa folosim 2 functii ca sa facem una putem folosi functia de mai jos :

StrLen proc pStr:DWORD
	mov eax,[esp+1*4]                  ; get pointer to string
	mov edx,eax
	xor ecx,ecx
@@:                                    
	test al,3                        
	jz @F                            
	mov cl,[eax]                     
	inc eax                          
	test cl,cl                       
	jnz @B                           
	sub cl,1
	jmp @1
@@:                                    
	mov edx,[eax]                      ; read first 4 bytes
	add eax,4                          ; increment pointer
	lea ecx,[edx-01010101h]            ; subtract 1 from each byte
	xor edx,-1                         ; invert all bytes
	and ecx,edx                        ; and these two
	and ecx,80808080h                  ; test all sign bits
	jz @B                              ; no zero bytes, continue loop
	mov edx,[esp+1*4]                  ; get pointer to string
	add edx,3                          ; pointer+3
	test ecx,00008080h                 ; test first two bytes
	jnz @F                           
	shr ecx,16                         ; not in the first 2 bytes
	add eax,2                        
@@:
	shl cl,1                           ; use carry