kolibrios/programs/develop/libraries/utils/trunk/_ftoa.inc
Akyltist b4f89a0b48 utils.obj fix: "0" converted
git-svn-id: svn://kolibrios.org@4887 a494cfbc-eb01-0410-851d-a64ba20cac60
2014-04-24 03:27:40 +00:00

305 lines
7.5 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;-----------------------------------------------------------------------------+
; ”ã­ªæ¨ï ¯¥à¥¢®¤  ¢¥é¥á⢥­­®£® ç¨á«  ¢ áâபã [ by ManHunter / PCL ] |
;-----------------------------------------------------------------------------|
; <EFBFBD> à ¬¥âàë: |
; lpFloat - 㪠§ â¥«ì ­  ¢¥é¥á⢥­­®¥ ç¨á«® TBYTE |
; lpResult - 㪠§ â¥«ì ­  áâபã-¯à¨¥¬­¨ª १ã«ìâ â  |
;-----------------------------------------------------------------------------+
proc FloatToString lpFloat:DWORD, lpResult:DWORD
; ‹®ª «ì­ë¥ ¯¥à¥¬¥­­ë¥
local digits_count:DWORD
local old_cw:WORD
local new_cw:WORD
local saved_float:TBYTE
local tmp1 rb 11h
local tmp2 rb 11h
; ‘®åà ­¨âì ¢á¥ à¥£¨áâàë
pusha
; “ª § â¥«ì ­  áâபã-¯à¨¥¬­¨ª
mov edi,[lpResult]
; <EFBFBD>â® ­®«ì?
mov esi,[lpFloat]
cmp dword [esi],0
jne loc_not_zero
cmp dword [esi+4],0
jne loc_not_zero
cmp word [esi+8],0
jne loc_not_zero
; ‡ ¯¨á âì ¢ áâப㠭®«ì
mov al,'0'
stosb
jmp loc_ret
loc_not_zero:
; ‘ª®¯¨à®¢ âì ç¨á«® ¢ «®ª «ì­ãî ¯¥à¥¬¥­­ãî
push edi
mov esi,[lpFloat]
lea edi,[saved_float]
movsd
movsd
movsw
pop edi
; —¨á«® ®âà¨æ â¥«ì­®¥?
cmp dword [saved_float+6],0
jge loc_not_signed
; <EFBFBD>ਢ¥á⨠ç¨á«® ª  ¡á®«îâ­®¬ã §­ ç¥­¨î
and byte [saved_float+9],7Fh
; ‡ ¯¨á âì ¢ áâப㠬¨­ãá
mov al,'-'
stosb
loc_not_signed:
; <EFBFBD>஢¥à¨âì ç¨á«® ­  ­ «¨ç¨¥ ¤à®¡­®© ç á⨠¨
; ¯®¤áç¨â âì ª®«¨ç¥á⢮ æ¨äà ¢ ­¥¬
fclex
; ‘®åà ­¨âì ã¯à ¢«ïî饥 á«®¢®
fstcw [old_cw]
; “áâ ­®¢¨âì ã¯à ¢«ïî饥 á«®¢®
mov [new_cw],0000001001111111b
fldcw [new_cw]
lea esi,[saved_float]
fld tbyte [esi]
fld st
; ‚뤥«¨âì ¬ ­â¨ááã ¨ ¯®à冷ª
fxtract
fstp st
fldlg2
; <EFBFBD>®«ãç¨âì ª®«¨ç¥á⢮ æ¨äà ¢ ç¨á«¥
fmulp st1,st
fistp [digits_count]
; …᫨ æ¨äà ¡®«ìè¥ 16, â® ç¨á«® ®â®¡à ¦ ¥âáï ¢
; ­®à¬ «¨§®¢ ­­®¬ ¢¨¤¥ á ¬ ­â¨áᮩ ¨ íªá¯®­¥­â®©
cmp [digits_count],10h
jnb loc_not_integer
; ç¨á«  ¥áâì ¤à®¡­ ï ç áâì?
fld st
frndint
fcomp st1
fstsw ax
test ah,01000000b
; „ , ®â®¡à ¦ âì ç¨á«® á ¤à®¡­®© ç áâìî
jz loc_not_integer
; –¥«®¥ ç¨á«® ¡¥§ ¤à®¡­®© ç á⨠¨ íªá¯®­¥­âë
lea eax,[tmp1]
fbstp [eax]
; <EFBFBD>¥à¥¢¥á⨠BCD-ç¨á«® ¢ áâபã
push edi
lea esi,[tmp1+8]
lea edi,[tmp2]
mov ecx, 9
@@:
std
xor eax,eax
lodsb
cld
rol ax,12
rol ah,4
add ax,'00'
stosw
loop @b
pop edi
; <EFBFBD>யãáâ¨âì «¨¤¨àãî騩 ­®«ì
mov eax,11h
mov ecx,[digits_count]
sub eax,ecx
inc ecx
lea esi,[tmp2+eax]
cmp byte [esi],'0'
jne @f
inc esi
dec ecx
@@:
; <EFBFBD>¥à¥­¥á⨠¯®«ã祭­®¥ ç¨á«® ¨§ ¢à¥¬¥­­®£® ¡ãä¥à 
rep movsb
jmp loc_clear_stack
loc_not_integer:
mov eax,10h
sub eax,[digits_count]
; <EFBFBD>८¡à §®¢ âì ç¨á«® ¢ 楫®¥ ¤® 16 à §à冷¢
mov ecx,eax
cmp eax,0
jge @f
neg eax
@@:
; „«ï ç¨á¥« ¡®«ìè¥ 0 ª®à४â¨à®¢ª  ®ªà㣫¥­¨ï ¢ áâ®à®­ã 0
mov [new_cw],0000101001111111b
cmp ecx,0
jge @f
mov [new_cw],0000011001111111b
@@:
; “áâ ­®¢¨âì ã¯à ¢«ïî饥 á«®¢®
fldcw [new_cw]
; ‚®§¢¥á⨠10 ¢ á⥯¥­ì ª®«¨ç¥á⢠ æ¨äà
fld [float2]
fld [float2]
@@:
fmul st,st1
dec eax
cmp eax,1
ja @b
; <EFBFBD>®ç¨áâ¨âì á⥪
fxch st1
fstp st
; …᫨ ç¨á«® ¬¥­ìè¥ 0, ⮠㬭®¦¨âì, ¨­ ç¥ à §¤¥«¨âì
cmp ecx,0
jge @f
fdivp st1,st
jmp loc_rounded
@@:
fmulp st1,st
loc_rounded:
; <EFBFBD>®«ã祭­®¥ §­ ç¥­¨¥ ¬¥­ìè¥ 1.0e16 ?
fcom [float1]
fstsw ax
test ah,1
jz @f
fmul [float2]
dec [digits_count]
@@:
; –¥«®¥ ç¨á«® ¡¥§ ¤à®¡­®© ç á⨠¨ íªá¯®­¥­âë
lea eax,[tmp1]
fbstp [eax]
; <EFBFBD>¥à¥¢¥á⨠BCD-ç¨á«® ¢ áâபã
push edi
lea esi,[tmp1+8]
lea edi,[tmp2]
mov ecx, 9
@@:
std
xor eax,eax
lodsb
cld
rol ax,12
rol ah,4
add ax,'00'
stosw
loop @b
pop edi
; —¨á«ã âॡã¥âáï ¬ ­â¨áá  ¨ íªá¯®­¥­â ?
lea esi,[tmp2+1]
mov ecx,[digits_count]
cmp ecx,-0Fh
jl loc_mantiss_and_exponent
cmp ecx,10h
jg loc_mantiss_and_exponent
; ‡ ¯®«­¨âì ¤à®¡­ãî ç áâì ç¨á« 
inc ecx
cmp ecx,0
jg @f
mov ax,'0.'
stosw
neg ecx
mov al,'0'
rep stosb
mov ecx,10h
jmp loc_fraction_filled
@@:
rep movsb
mov al,'.'
stosb
mov ecx,10h
sub ecx,[digits_count]
loc_fraction_filled:
rep movsb
jmp @f
loc_clear_fraction:
; “¤ «¨âì § ¢¥àè î騥 ­ã«¨ ¤à®¡­®© ç áâ¨
dec edi
@@:
cmp byte [edi-1],'0'
jz loc_clear_fraction
cmp byte [edi-1],'.'
jnz @f
dec edi
@@:
jmp loc_clear_stack
loc_mantiss_and_exponent:
; „஡­ ï ç áâì ¬ ­â¨ááë
movsb
mov al,'.'
stosb
movsd
movsd
movsw
; “¤ «¨âì § ¢¥àè î騥 ­ã«¨ ¤à®¡­®© ç áâ¨
@@:
cmp byte [edi-1],'0'
jne @f
cmp byte [edi-2],'.'
je @f
dec edi
jmp @b
@@:
; ‘¨¬¢®« ¨ §­ ª íªá¯®­¥­âë
mov al,'e'
stosb
mov al,'+'
mov ebx,[digits_count]
cmp ebx, 0
jge @f
mov al,'-'
neg ebx
@@:
stosb
; ‡­ ç¥­¨¥ íªá¯®­¥­âë
mov eax,ebx
mov ecx,10
mov ebx,4
@@:
dec ebx
xor edx,edx
div ecx
add dl,'0'
mov [tmp1+ebx],dl
or ebx,ebx
jnz @b
; <EFBFBD>யãáâ¨âì «¨¤¨àãî騥 ­ã«¨ íªá¯®­¥­âë
mov ecx,4
lea esi,[tmp1]
@@:
lodsb
cmp al,'0'
jne @f
dec ecx
jmp @b
@@:
dec esi
rep movsb
loc_clear_stack:
; ‚®ááâ ­®¢¨âì ã¯à ¢«ïî饥 á«®¢®
fldcw [old_cw]
loc_ret:
; Žª®­ç ­¨¥ áâப¨
mov al,0
stosb
; ‚®ááâ ­®¢¨âì ¢á¥ à¥£¨áâàë
popa
ret
float1 dq 1.0e16
float2 dq 10.0
endp