ALARM! Steve! It's especialy for you. I take this section not only as for algo discussion but also for existing proc espec. in M32lib. I found some exceptive sub array for Terje Mathisen rule... Well no! ..I've started from a wrong place, from this point I'll never be able finish the explonations with my English :) Let's start again: It's about new optimized versions of dwtoa and udw2str, there are little subarray of 32 bit number wich will be converted incorrectly using these optimized procs(Try for ex. 4FFFFFFFh). I found the bugs, analyzed it, found solution (a little bit awkward for me though, when I find better I let you know but it still much faster (2,5 times) then original procs) REPLACE NEW VERSIONS OF dwtoa.asm and udw3str with this code:

dwtoa.asm:
-------------------------
      .386
      .model flat, stdcall  ; 32 bit memory model
      option casemap :none  ; case sensitive

    .code

; #########################################################################

dwtoa proc public uses esi edi dwValue:DWORD, lpBuffer:PTR BYTE


   	 mov	eax, dwValue
	 mov edi, 
	  or eax,eax
	  jnz sign
zero:     mov word ptr ,30h
	     ret
sign:	  jns pos
	  mov byte ptr ,'-'
	  neg eax
	  inc edi
pos:	  
	mov ecx,429496730
	  mov esi, edi

	.while (eax > 0)
	mov ebx,eax
	imul ecx
	mov eax,edx
	lea edx,
	add edx,edx
	.IF edx > ebx
	sub edx,10
	dec eax
	.ENDIF
	sub ebx,edx
	add bl,'0'
	mov ,bl
	inc edi
	.endw

    mov byte ptr , 0	; terminate the string

    ; We now have all the digits, but in reverse order.

    .while (esi < edi)
      dec edi
      mov al, 
      mov ah, 
      mov , al
      mov , ah
      inc esi
    .endw
    ret

dwtoa endp

; #########################################################################

end
;---------------------------------------------
udw2str:

    .386
    .model flat, stdcall  ; 32 bit memory model
    option casemap :none  ; case sensitive


    .code

;#########################################################################

udw2str proc uses esi ebx dwNumber:DWORD, pszString:DWORD

	mov	eax, 
	mov	esi, 
	mov ecx,429496730
@@redo:	                   	  
	mov ebx,eax	   
	mul ecx		   
	mov eax,edx
	lea edx,
	add edx,edx
	.IF edx > ebx
	sub edx,10
	dec eax
	.ENDIF
	sub ebx,edx
	add bl,'0'
	mov ,bl
	inc esi
	test	eax, eax
	jnz	@@redo
	mov	byte ptr ,0
	mov	ebx,
	jmp	@@chks
@@invs:	dec	esi
	mov	al,
	mov	dl,
	mov	, al
	mov	, dl
	inc	ebx
@@chks:	cmp	ebx, esi
	jb	@@invs
	ret

udw2str endp

;#########################################################################
end

This message was edited by Hiroshimator, on 3/29/2001 4:01:54 PM
Posted on 2001-03-28 03:17:00 by The Svin