Assembly code snippets
Details
Title | 64 bit to dec ASCIIZ - 2 with MMX |
---|---|
Author | The Svin |
Submitted by: | The Svin |
Date added: | 2002-02-20 15:34:50 |
Date modified: | 2002-02-20 15:35:23 |
Comments
This version a little bit faster with big numbers
Snippet
.586
.MMX
.model flat,stdcall
option casemap:none
.data
ALIGN 8
mmxb0F dq 0F0F0F0F0F0F0F0Fh
mmxb30 dq 3030303030303030h
.code
Q2Ammxf proc uses edi lpBuffer,lpNumber
mov ecx,lpNumber
mov edi,lpBuffer
mov eax,[ecx]
mov edx,[ecx+4]
D05H equ 045639182h
D05L equ 044F40000h
D04H equ 03782DACEh
D04L equ 09D900000h
D01H equ 00DE0B6B3h
D01L equ 0A7640000h
QtoA:
sub esp,12
xor ecx,ecx
sub eax,D01L
sbb edx,D01H
jb @@a01f
sub eax,D04L
sbb edx,D04H
jb @@a05
mov cl,05h
sub eax,D05L
sbb edx,D05H
jb @@a05
mov cl,15h
sub eax,D05L
sbb edx,D05H
jae @@l01
mov cl,10h
@@a05:
add eax,D05L
adc edx,D05H
@@l01: inc ecx
sub eax,D01L
sbb edx,D01H
jae @@l01
dec ecx
@@a01f:
add eax,D01L
adc edx,D01H
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
Q2Ammxf endp
end
.MMX
.model flat,stdcall
option casemap:none
.data
ALIGN 8
mmxb0F dq 0F0F0F0F0F0F0F0Fh
mmxb30 dq 3030303030303030h
.code
Q2Ammxf proc uses edi lpBuffer,lpNumber
mov ecx,lpNumber
mov edi,lpBuffer
mov eax,[ecx]
mov edx,[ecx+4]
D05H equ 045639182h
D05L equ 044F40000h
D04H equ 03782DACEh
D04L equ 09D900000h
D01H equ 00DE0B6B3h
D01L equ 0A7640000h
QtoA:
sub esp,12
xor ecx,ecx
sub eax,D01L
sbb edx,D01H
jb @@a01f
sub eax,D04L
sbb edx,D04H
jb @@a05
mov cl,05h
sub eax,D05L
sbb edx,D05H
jb @@a05
mov cl,15h
sub eax,D05L
sbb edx,D05H
jae @@l01
mov cl,10h
@@a05:
add eax,D05L
adc edx,D05H
@@l01: inc ecx
sub eax,D01L
sbb edx,D01H
jae @@l01
dec ecx
@@a01f:
add eax,D01L
adc edx,D01H
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
Q2Ammxf endp
end