hello,

can anyone help me optimize this proc, i'll pass to it 25 chars and format it addin a - well, check my code

Format proc near innumber:DWORD

lea edi, outbuffer
mov esi, innumber
mov ecx, 5
comm:
lodsb
stosb
lodsb
stosb
lodsb
stosb
lodsb
stosb
lodsb
stosb
mov al, 02Dh
stosb
loopnz comm
and byte ptr ,0
ret
Format endp

these lodsb's are weird :/ i feel there is another way, i want to optmize first for size then speed :-)

gimme suggestions and stuff

thanks a lot
The Keeper.
Posted on 2002-07-14 22:56:09 by The Keeper
Maybe, something like this:
	OPTION PROLOGUE:NONE

OPTION EPILOGUE:NONE

Format PROC near innumber:DWORD
pop edx
pop esi
mov edi, OFFSET outbuffer
mov eax, '-' + 500h
@@: movsd
movsb
stosb
dec ah
jne @B
mov [edi-1],ah
jmp edx
Format ENDP

OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF
Didn't assemble it, let me know if it works. :grin:

You wouldn't be working on some bad software, would you? Why would you need this algo size optimized? Must be for a contest 'er something?

Fixed to add Nexo's suggestion below.
Posted on 2002-07-14 23:43:04 by bitRAKE
"comm" - reserved keyword :grin:



mov al,'-'
comm:
movsd
movsb
stosb
dec cl
jne comm
Posted on 2002-07-15 10:03:08 by Nexo
Use of the string instructions without the REP prefix is a documented bad performer as is the LOOPNZ instruction. The algo needs a rewrite to avoid these problems.

These two instructions can be replaced with MOVSB,


lodsb
stosb

I would not waste your time chasing a size optimisation but if the algo is speed critical, it can be rewritten to get some reasonable speed gains if it is done right.

Even with string instructions, a loop of the type


mov ecx, count
mov esi, source
mov edi, destination
rep movsb

would be faster but I would imagine that a direct addressing algo would be measurably faster again.

Regards,

hutch@movsd.com
Posted on 2002-07-15 21:05:58 by hutch--