kolibrios-fun/programs/develop/libraries/utils/trunk/_atof.inc
Akyltist 9b11245e08 Add COFF libraries "utils.obj" atof,ftoa,random
support for exponent, high accuracy, not normalized form of writing

git-svn-id: svn://kolibrios.org@4721 a494cfbc-eb01-0410-851d-a64ba20cac60
2014-03-31 05:57:30 +00:00

300 lines
6.6 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.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;-----------------------------------------------------------------------------+
; ”ã­ªæ¨ï ¯à¥®¡à §®¢ ­¨ï áâப¨ ¢ ¢¥é¥á⢥­­®¥ ç¨á«® [ by ManHunter / PCL ] |
;-----------------------------------------------------------------------------|
; <EFBFBD> à ¬¥âàë: |
; lpStr - 㪠§ â¥«ì ­  ¨á室­ãî áâப㠢 ä®à¬ â¥ ASCIIZ |
; lpResult - 㪠§ â¥«ì ­  ¯¥à¥¬¥­­ãî-¯à¨¥¬­¨ª §­ ç¥­¨ï |
; <EFBFBD>  ¢ë室¥: |
; EAX = 1 - áâப  ãᯥ譮 ¯à¥®¡à §®¢ ­  |
; EAX = 0 - áâப  ­¥ ¬®¦¥â ¡ëâì ¯à¥®¡à §®¢ ­  ¢ ç¨á«® |
;-----------------------------------------------------------------------------+
proc string2float lpStr:DWORD, lpResult:DWORD
; ‹®ª «ì­ë¥ ¯¥à¥¬¥­­ë¥
locals
dot dd ? ; “ª § â¥«ì ­  ¤à®¡­ãî ç áâì
exp dd ? ; “ª § â¥«ì ­  íªá¯®­¥­âã
digit dd ? ; –¨äà 
endl
pusha
; <EFBFBD>஢¥àª  áâப¨ ­  ¢ «¨¤­®áâì
mov [digit],1
mov [exp],0
mov [dot],0
mov esi,[lpStr]
; Œ¨­ãá ¨«¨ ¯«îá ¬®¦¥â ¡ëâì ⮫쪮 ¢ ­ ç «¥
cmp byte [esi],'-'
je @f
cmp byte [esi],'+'
jne .loc_chk_loop
@@:
inc esi
; <EFBFBD>®á«¥ §­ ª  ­¥ ¬®¦¥â ¡ëâì ­ã«ï
cmp byte [esi],0
je .loc_chk_error
.loc_chk_loop:
; áâப¥ ¤®«¦­ë ¡ëâì æ¨äà, íªá¯®­¥­â  ¨ ­¥ ¡®«¥¥ ®¤­®© â®çª¨
lodsb
or al,al
jz .loc_chk_complete
cmp al,'e'
je .loc_chk_exp
cmp al,'E'
je .loc_chk_exp
cmp al,'.'
je .loc_chk_dot
cmp al,'0'
jb .loc_chk_error
cmp al,'9'
ja .loc_chk_error
jmp .loc_chk_loop
.loc_chk_dot:
; ’®çª  ¢ áâப¥ 㦥 ¥áâì?
cmp [dot],0
; ‘âப  ¨¬¥¥â ­¥ª®à४â­ë© ä®à¬ â
jne .loc_chk_error
; <EFBFBD>ªá¯®­¥­â  㦥 ¥áâì?
cmp [exp],0
; ‘âப  ¨¬¥¥â ­¥ª®à४â­ë© ä®à¬ â
jne .loc_chk_error
; “ª § â¥«ì ­  ¤à®¡­ãî ç áâì
mov [dot],esi
jmp .loc_chk_loop
.loc_chk_exp:
; <EFBFBD>ªá¯®­¥­â  㦥 ¥áâì?
cmp [exp],0
; ‘âப  ¨¬¥¥â ­¥ª®à४â­ë© ä®à¬ â
jne .loc_chk_error
; “ª § â¥«ì ­  ­ ç «® íªá¯®­¥­âë
mov [exp],esi
; ‘ࠧ㠯®á«¥ íªá¯®­¥­âë ­¥ ¬®¦¥â ¡ëâì ­ã«ï
cmp byte [esi],0
je .loc_chk_error
; <EFBFBD>®á«¥ íªá¯®­¥­âë ¬®¦¥â ¡ëâì §­ ª
cmp byte [esi],'-'
je @f
cmp byte [esi],'+'
jne .loc_chk_loop
@@:
inc esi
; ‘ࠧ㠯®á«¥ ¬¨­ãá  ­¥ ¬®¦¥â ¡ëâì ­ã«ï
cmp byte [esi],0
je .loc_chk_error
; <EFBFBD>஢¥à¨âì á«¥¤ãî騩 ᨬ¢®«
jmp .loc_chk_loop
.loc_chk_error:
; ‘âப  ­¥ ï¥âáï ç¨á«®¬
mov [digit],0
jmp .loc_ret
.loc_chk_complete:
; ˆ­¨æ¨ «¨§ æ¨ï ᮯà®æ¥áá®à 
finit
; <EFBFBD> ç «ì­®¥ §­ ç¥­¨¥ ç¨á« 
fldz
; Œ­®¦¨â¥«ì ¨ ¤¥«¨â¥«ì
mov [digit],10
fild dword [digit]
; ‡ ¯¨áì §­ ç¥­¨© ¤® § ¯ï⮩
mov esi,[lpStr]
; ­ ç «¥ áâப¨ ¬¨­ãá?
cmp byte [esi],'-'
je @f
cmp byte [esi],'+'
jne .loc_before_dot
@@:
inc esi
; <EFBFBD>८¡à §®¢ ­¨¥ ç¨á«  ¤® § ¯ï⮩
.loc_before_dot:
lodsb
; Š®­¥æ áâப¨?
or al,al
jz .loc_complete
cmp al,'.'
je .loc_complete_before_dot
cmp al,'e'
je .loc_exp
cmp al,'E'
je .loc_exp
; Žç¥à¥¤­ ï æ¨äà 
sub al,'0'
movzx eax,al
mov [digit],eax
; ‡ ¯¨á âì
fild dword [digit]
fxch st2
fmul st0,st1
fxch st2
fadd st2,st0
ffree st0 ; <EFBFBD>®ç¨áâ¨âì á⥪
fincstp
jmp .loc_before_dot
; <EFBFBD>८¡à §®¢ ­¨¥ ¤à®¡­®© ç á⨠ç¨á« 
.loc_complete_before_dot:
; „஡­ ï ç áâì ¥áâì?
cmp [dot],0
je .loc_complete_after_dot
; <EFBFBD>ªá¯®­¥­â  ¥áâì?
cmp [exp],0
je @f
; “ª § â¥«ì ­  ­ ç «® íªá¯®­¥­âë
mov esi,[exp]
jmp .loc_start_after_dot
@@:
; ˆ­ ç¥ ¯¥à¥­¥á⨠㪠§ â¥«ì ­  ª®­¥æ áâப¨
xor ecx,ecx
dec ecx
xor eax,eax
mov edi,esi
repne scasb
mov esi,edi
.loc_start_after_dot:
std
dec esi
dec esi
; „஡­ ï ç áâì
fldz
fxch st1
.loc_after_dot:
lodsb
; Š®­¥æ ¤à®¡­®© ç áâ¨?
cmp al,'.'
je .loc_complete_after_dot
; Žç¥à¥¤­ ï æ¨äà 
sub al,'0'
movzx eax,al
mov [digit],eax
; ‡ ¯¨á âì
fild dword [digit]
fadd st2,st0
fxch st2
fdiv st0,st1
fxch st2
ffree st0 ; <EFBFBD>®ç¨áâ¨âì á⥪
fincstp
jmp .loc_after_dot
.loc_complete_after_dot:
; ‘¡à®á¨âì ä« £ ­ ¯à ¢«¥­¨ï
cld
ffree st0 ; <EFBFBD>®ç¨áâ¨âì á⥪
fincstp
; ‘«®¦¨âì ¤à®¡­ãî ¨ 楫ãî ç áâì
fadd st1,st0
.loc_exp:
; <EFBFBD>ªá¯®­¥­â  ¥áâì?
cmp [exp],0
je .loc_complete
; <EFBFBD>®«ãç¨âì §­ ç¥­¨¥ íªá¯®­¥­âë
xor ecx,ecx
mov esi,[exp]
; ­ ç «¥ áâப¨ ¬¨­ãá?
cmp byte [esi],'-'
je @f
cmp byte [esi],'+'
jne .loc_start_exp
@@:
inc esi
.loc_start_exp:
lodsb
or al,al
jz .loc_end_exp
sub al,'0'
movzx eax,al
imul ecx,10
add ecx,eax
jmp .loc_start_exp
.loc_end_exp:
or ecx,ecx
jz .loc_complete
ffree st0 ; <EFBFBD>®ç¨áâ¨âì á⥪
fincstp
mov [digit],10
fild dword [digit]
; „¥«¨âì ¨«¨ 㬭®¦ âì?
mov esi,[exp]
cmp byte [esi],'-'
je .loc_exp_divide
.loc_exp_multiple:
fmul st1,st0
loop .loc_exp_multiple
jmp .loc_complete
.loc_exp_divide:
fdiv st1,st0
loop .loc_exp_divide
.loc_complete:
ffree st0 ; <EFBFBD>®ç¨áâ¨âì á⥪
fincstp
; ­ ç «¥ áâப¨ ¬¨­ãá?
mov esi,[lpStr]
cmp byte [esi],'-'
jne @f
; ˆ§¬¥­¨âì §­ ª ç¨á« 
fchs
@@:
; ‡ ¯¨á âì §­ ç¥­¨¥ ¢ ï祩ªã ¯ ¬ïâ¨
mov eax,[lpResult]
; …᫨ âॡã¥âáï ¯®¢ë襭­ ï â®ç­®áâì, â® ¯à¨¥¬­¨ª
; ¤®«¦¥­ ¨¬¥âì à §¬¥à QWORD,   á«¥¤ãîéãî ª®¬ ­¤ã
; ­ ¤® § ¬¥­¨âì ­  fstp qword [eax]
fstp tword [eax]
; “ᯥ譮¥ ¯à¥®¡à §®¢ ­¨¥
mov [digit],1
.loc_ret:
popa
; <EFBFBD>¥§ã«ìâ â ¯à¥®¡à §®¢ ­¨ï
mov eax,[digit]
ret
endp