Assembly code snippets
Details
Title | Set comma delimiter in decimal strings |
---|---|
Author | The Svin |
Submitted by: | The Svin |
Date added: | 2002-02-20 15:42:09 |
Date modified: | 2002-05-15 11:30:52 |
Comments
This proc makes 1,000,234 from 1000234.
The version of the proc developed with bitRake help.
Snippet
InsertComma PROC uses esi edi len,lpszStringIn,lpszStringOut
or ecx,-1
mov eax,len
mov esi,lpszStringIn
mov edi,lpszStringOut
@@: inc ecx ;number of commas
sub eax,3
jnbe @B
mov edx,[esi]
; remainder & back one for 2Ch in low byte of EAX loop below
lea esi,[esi][eax][3][-1]
mov [edi],edx
dec ecx
; remainder & back four for ADD before MOV in loop below
lea edi,[edi][eax][3][-4]
js @r ; if length less than four we are done
jne @F
mov byte ptr [edi][4],2Ch
mov eax,[esi+1]
mov [edi+1][4],eax
jmp @r
@@: mov eax,[esi]
add esi,3
mov al,2Ch
add edi,4
dec ecx
mov [edi],eax
jns @B
mov byte ptr [edi+4],0
@r: ret
InsertComma ENDP
or ecx,-1
mov eax,len
mov esi,lpszStringIn
mov edi,lpszStringOut
@@: inc ecx ;number of commas
sub eax,3
jnbe @B
mov edx,[esi]
; remainder & back one for 2Ch in low byte of EAX loop below
lea esi,[esi][eax][3][-1]
mov [edi],edx
dec ecx
; remainder & back four for ADD before MOV in loop below
lea edi,[edi][eax][3][-4]
js @r ; if length less than four we are done
jne @F
mov byte ptr [edi][4],2Ch
mov eax,[esi+1]
mov [edi+1][4],eax
jmp @r
@@: mov eax,[esi]
add esi,3
mov al,2Ch
add edi,4
dec ecx
mov [edi],eax
jns @B
mov byte ptr [edi+4],0
@r: ret
InsertComma ENDP