Assembly code snippets
Details
Title | 64 bit to deciamal ASCIIZ with MMX |
---|---|
Author | The Svin |
Submitted by: | The Svin |
Date added: | 2002-02-20 15:31:56 |
Date modified: | 2002-02-20 15:31:56 |
Comments
Convertion of 64 bit unsigned integer to decimal ASCIIZ string
Snippet
.586
.MMX
.model flat,stdcall
option casemap:none
.data
ALIGN 8
mmxb0F dq 0F0F0F0F0F0F0F0Fh
mmxb30 dq 3030303030303030h
num dq 12345678901234567890
.data?
buffer db 24 dup (?)
.code
mov edx,dword ptr num+4
mov eax,dword ptr num
mov edi, offset buffer
N19H EQU 00DE0B6B3H
N19L EQU 0A7640000H
N20H EQU 08AC72304H
N20L EQU 089E80000H
Q2Ammx proc uses edi lpBuffer, lpNumber
mov ecx,lpNumber
mov eax,[ecx]
mov edx,[ecx+4]
mov edi,lpBuffer
sub esp,12
xor ecx,ecx
cmp edx,N19H
jb @@nm18
jne @@cp20
cmp eax,N19L
jb @@nm18
@@cp20:
cmp edx,N20H
jb @@do19
jne @@do20
cmp eax,N20L
jb @@do19
@@do20:
mov cl,10h-1
sub eax,N20L
sbb edx,N20H
@@lp19:
inc ecx
@@do19:
sub eax,N19L
sbb edx,N19H
jae @@lp19
add eax,N19L
adc edx,N19H
@@nm18:
push edx
push eax
fild qword ptr [esp]
fbstp [esp]
mov [esp+9],ecx
mov edx,2
cmp dword ptr [esp+8],0
jne @@dg16
cmp dword ptr [esp+4],1
sbb edx,1
@@dg16:
bsr ecx,[esp+edx*4]
je @@zero
shr ecx,3
lea eax,[ecx+4*edx]
lea edx,[eax+eax]
cmp byte ptr [esp][eax],10h
sbb edx,-1
movq mm(7),mmxb0F
movq mm(6),mmxb30
movq mm(0),[esp]
movq mm(4),[esp+8]
movq mm(1),mm(0)
psrlq mm(1),4
pand mm(0),mm(7)
por mm(0),mm(6)
pand mm(1),mm(7)
por mm(1),mm(6)
movq mm(2),mm(0)
punpcklbw mm(0),mm(1)
movq [esp],mm(0)
punpckhbw mm(2),mm(1)
movq [esp+8],mm(2)
movq mm(5),mm(4)
psrlq mm(5),4
pand mm(4),mm(7)
por mm(4),mm(6)
pand mm(5),mm(7)
por mm(5),mm(6)
punpcklbw mm(4),mm(5)
movd [esp+16],mm(4)
emms
@@lpS:
mov eax,[esp+edx-3]
bswap eax
mov [edi],eax
add edi,4
sub edx,4
jns @@lpS
mov byte ptr [edi][edx][1],0
add esp,20
ret
@@zero:
mov dword ptr [edi],'0'
add esp,20
ret
Q2Ammx endp
end
.MMX
.model flat,stdcall
option casemap:none
.data
ALIGN 8
mmxb0F dq 0F0F0F0F0F0F0F0Fh
mmxb30 dq 3030303030303030h
num dq 12345678901234567890
.data?
buffer db 24 dup (?)
.code
mov edx,dword ptr num+4
mov eax,dword ptr num
mov edi, offset buffer
N19H EQU 00DE0B6B3H
N19L EQU 0A7640000H
N20H EQU 08AC72304H
N20L EQU 089E80000H
Q2Ammx proc uses edi lpBuffer, lpNumber
mov ecx,lpNumber
mov eax,[ecx]
mov edx,[ecx+4]
mov edi,lpBuffer
sub esp,12
xor ecx,ecx
cmp edx,N19H
jb @@nm18
jne @@cp20
cmp eax,N19L
jb @@nm18
@@cp20:
cmp edx,N20H
jb @@do19
jne @@do20
cmp eax,N20L
jb @@do19
@@do20:
mov cl,10h-1
sub eax,N20L
sbb edx,N20H
@@lp19:
inc ecx
@@do19:
sub eax,N19L
sbb edx,N19H
jae @@lp19
add eax,N19L
adc edx,N19H
@@nm18:
push edx
push eax
fild qword ptr [esp]
fbstp [esp]
mov [esp+9],ecx
mov edx,2
cmp dword ptr [esp+8],0
jne @@dg16
cmp dword ptr [esp+4],1
sbb edx,1
@@dg16:
bsr ecx,[esp+edx*4]
je @@zero
shr ecx,3
lea eax,[ecx+4*edx]
lea edx,[eax+eax]
cmp byte ptr [esp][eax],10h
sbb edx,-1
movq mm(7),mmxb0F
movq mm(6),mmxb30
movq mm(0),[esp]
movq mm(4),[esp+8]
movq mm(1),mm(0)
psrlq mm(1),4
pand mm(0),mm(7)
por mm(0),mm(6)
pand mm(1),mm(7)
por mm(1),mm(6)
movq mm(2),mm(0)
punpcklbw mm(0),mm(1)
movq [esp],mm(0)
punpckhbw mm(2),mm(1)
movq [esp+8],mm(2)
movq mm(5),mm(4)
psrlq mm(5),4
pand mm(4),mm(7)
por mm(4),mm(6)
pand mm(5),mm(7)
por mm(5),mm(6)
punpcklbw mm(4),mm(5)
movd [esp+16],mm(4)
emms
@@lpS:
mov eax,[esp+edx-3]
bswap eax
mov [edi],eax
add edi,4
sub edx,4
jns @@lpS
mov byte ptr [edi][edx][1],0
add esp,20
ret
@@zero:
mov dword ptr [edi],'0'
add esp,20
ret
Q2Ammx endp
end