add exponent reading ..e+.., ..e-..

git-svn-id: svn://kolibrios.org@7615 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2019-03-21 20:08:47 +00:00
parent 6af7c83564
commit 0c01e81393

View File

@ -39,9 +39,10 @@ Data_BCD DT ?
Data_Flag DB ?
; ‡­ ª १ã«ìâ â  (¥á«¨ ­¥ 0 - ®âà¨æ â¥«ì­®¥ ç¨á«®)
Data_Sign DB ?
; ‡­ ª १ã«ìâ â  - 0 ¤«ï ..e+.. ¨ 1 ¤«ï ..e-..
Data_Sign_Exp DB ?
db 0 ;㪠§ â¥«ì ­  ᤢ¨£ ¢ ¯ ¬ïâ¨
align 4
; ‘âப  ¤«ï åà ­¥­¨ï ç¨á«  ¢ ª®¤¥ ASCII
Data_String DB 32 DUP (?)
@ -75,8 +76,7 @@ DoubleFloat_to_String:
je .NoShifts ;­¥â æ¨äà ¯®á«¥ § ¯ï⮩
jl .Error ;®è¨¡ª 
dec BX
shl BX, 3 ;㬭®¦ ¥¬ ­  8
add EBX, MConst
lea ebx,[MConst+8*ebx]
fmul qword [EBX] ;㬭®¦¨âì ­  ª®­áâ ­âã
.NoShifts:
; ˆ§¢«¥çì ç¨á«® ¢ ª®¤¥ BCD
@ -197,36 +197,37 @@ String_to_DoubleFloat:
mov word [Data_BCD+8],0
; Žç¨é ¥¬ ¡ ©â §­ ª 
mov [Data_Sign],0
; ‡ ­®á¨¬ ¢ SI 㪠§ â¥«ì ­  áâபã
mov ESI, Data_String
; ‡ ­®á¨¬ ¢ esi 㪠§ â¥«ì ­  áâபã
mov esi, Data_String
; <EFBFBD>யã᪠¥¬ ¯à®¡¥«ë ¯¥à¥¤ ç¨á«®¬
mov ecx,64 ;§ é¨â  ®â § æ¨ª«¨¢ ­¨ï
.ShiftIgnore:
lodsb
cmp AL,' '
jne .ShiftIgnoreEnd
loop .ShiftIgnore
jmp .Error
cmp al,' '
jne .ShiftIgnoreEnd
loop .ShiftIgnore
jmp .Error
align 4
.ShiftIgnoreEnd:
; <EFBFBD>஢¥à塞 §­ ª ç¨á« 
cmp AL,'-'
cmp al,'-'
jne .Positive
mov [Data_Sign],80h
lodsb
.Positive:
mov [Data_Flag],0 ;¯à¨§­ ª ­ «¨ç¨ï â®çª¨
mov DX,0 ;¯®§¨æ¨ï â®çª¨
xor edx,edx ;¯®§¨æ¨ï â®çª¨
mov ecx,18 ;¬ ªá. ç¨á«® à §à冷¢
align 4
.ASCIItoBCDConversion:
cmp AL,'.' ;â®çª ?
cmp al,'.' ;â®çª ?
jne .NotDot
cmp [Data_Flag],0 ;â®çª  ­¥ ¢áâà¥ç « áì?
jne .Error
jne .Error ;¥á«¨ â®çª  㦥 ¡ë« 
mov [Data_Flag],1
lodsb
cmp AL,0 ;ª®­¥æ áâப¨?
jne .NotDot
or al,al ;ª®­¥æ áâப¨?
jnz .NotDot
jmp .ASCIItoBCDConversionEnd
align 4
.NotDot:
@ -234,71 +235,146 @@ align 4
; ¥á«¨ ®­  ¥é¥ ­¥ ¢áâà¥ç « áì
cmp [Data_Flag],0
jnz .Figures
inc DX
inc edx
.Figures:
cmp al,'e'
je .exp_form
cmp al,'E'
jne @f
.exp_form:
call string_ExpForm ;¥á«¨ ç¨á«® ¢ ä®à¬ â¥ ..e..
or al,al
jnz .Error
jmp .ASCIItoBCDConversionEnd
@@:
; ‘¨¬¢®«ë ç¨á«  ¤®«¦­ë ¡ëâì æ¨äà ¬¨
cmp AL,'0'
cmp al,'0'
jb .Error
cmp AL,'9'
cmp al,'9'
ja .Error
; <EFBFBD>¨è¥¬ ®ç¥à¥¤­ãî æ¨äàã ¢ ¬« ¤èãî â¥âà ¤ã BCD
and AL,0Fh
or byte [Data_BCD],AL
and al,15 ;ᨬ¢®«ë 0-9 ¯¥à¥¢®¤¨¬ ¢ ç¨á«®
or byte [Data_BCD],al
; <EFBFBD>஢¥àª  ­  ª®­¥æ áâப¨
cmp byte [ESI],0
cmp byte [esi],0
je .ASCIItoBCDConversionEnd
; ‘¤¢¨£ ¥¬ BCD ­  4 à §à鸞 ¢«¥¢®
; (ᤢ¨£ ¥¬ áâ à訥 2 ¡ ©â )
mov AX,word [Data_BCD+6]
shld word [Data_BCD+8],AX,4
mov ax,word [Data_BCD+6]
shld word [Data_BCD+8],ax,4
; (ᤢ¨£ ¥¬ á।­¨¥ 4 ¡ ©â )
mov EAX, dword [Data_BCD]
shld dword [Data_BCD+4],EAX,4
mov eax,dword [Data_BCD]
shld dword [Data_BCD+4],eax,4
; (ᤢ¨£ ¥¬ ¬« ¤è¨¥ 4 ¡ ©â )
shl dword [Data_BCD],4
; ‡ £à㦠¥¬ á«¥¤ãî騩 ᨬ¢®« ¢ AL
lodsb
loop .ASCIItoBCDConversion
loop .ASCIItoBCDConversion ;¥á«¨ ­¥ ª®¬¯¨«. â® ¯®áâ ¢¨âì dec ecx, jnz ...
; …᫨ 19-© ᨬ¢®« ­¥ 0 ¨ ­¥ â®çª ,
; â® ®è¨¡ª  ¯¥à¥¯®«­¥­¨ï
cmp AL,'.'
cmp al,'.'
jne .NotDot2
inc ecx
inc ecx ;¯à®¯ã᪠â®çª¨ ¢ ª®­æ¥ ®ç¥­ì ¡®«ì讣® ç¨á« 
lodsb
.NotDot2:
cmp AL,0
jne .Error ;¯¥à¥¯®«­¥­¨¥ à §à來®© á¥âª¨
or al,al ;¯¥à¥¯®«­¥­¨¥ à §à來®© á¥âª¨?
jz .ASCIItoBCDConversionEnd
align 4
.Error: ; <EFBFBD>ਠ«î¡®© ®è¨¡ª¥ ®¡­ã«¨âì १ã«ìâ â
fldz ;§ ­¥á⨠­®«ì á á⥪ ᮯà®æ¥áá®à 
fstp [Data_Double]
jmp .End
; <EFBFBD><EFBFBD>…Ž<EFBFBD><EFBFBD>€‡Žœ —ˆ‘‹Ž ˆ‡ ŠŽ„€ BCD …™…<EFBFBD><EFBFBD>Ž… —ˆ‘‹Ž
.ASCIItoBCDConversionEnd:
; ‚¯¨á âì §­ ª ¢ áâ à訩 ¡ ©â
mov AL,[Data_Sign]
mov byte [Data_BCD+9],AL
mov al,[Data_Sign]
mov byte [Data_BCD+9],al
; ‘¡à®á¨âì ॣ¨áâàë ᮯà®æ¥áá®à 
fninit
; ‡ £à㧨âì ¢ ᮯà®æ¥áá®à ç¨á«® ¢ BCD-ä®à¬ â¥
fbld [Data_BCD]
; ‚ëç¨á«¨âì ­®¬¥à ¤¥«¨â¥«ï
mov EBX,18+1
sub BX,CX
sub BX,DX
cmp EBX,0
je .NoDiv
dec EBX
shl EBX,3 ;㬭®¦ ¥¬ ­  8
add EBX, MConst
fdiv qword [EBX] ;à §¤¥«¨âì ­  ª®­áâ ­âã
.NoDiv:; ‚ë£à㧨âì ç¨á«® ¢ ¤¢®¨ç­®¬ ä®à¬ â¥
fstp [Data_Double]
jmp .End
align 4
.Error:; <EFBFBD>ਠ«î¡®© ®è¨¡ª¥ ®¡­ã«¨âì १ã«ìâ â
fldz ;§ ­¥á⨠­®«ì á á⥪ ᮯà®æ¥áá®à 
fstp [Data_Double]
; ‚ëç¨á«¨âì ­®¬¥à ¤¥«¨â¥«ï ¨«¨ ¬­®¦¨â¥«ï
lea ebx,[ecx+edx-18]
cmp ebx,0
jle .NoMul ;¥á«¨ ç¨á«® e-..
dec ebx
jz .NoDiv ;¥á«¨ ç¨á«® e+0
dec ebx
lea ebx,[MConst+8*ebx]
fmul qword [ebx] ;㬭®¦¨âì ­  ª®­áâ ­âã (¤«ï ç¨á¥« á ¯à¨áâ ¢ª®© e+..)
jmp .NoDiv
.NoMul:
neg ebx
lea ebx,[MConst+8*ebx]
fdiv qword [ebx] ;à §¤¥«¨âì ­  ª®­áâ ­âã
.NoDiv: ;‚ë£à㧨âì ç¨á«® ¢ ¤¢®¨ç­®¬ ä®à¬ â¥
fstp [Data_Double]
.End:
popad
ret
;output:
; eax - 1 if error
; edx += size
align 4
proc string_ExpForm uses ebx
mov [Data_Sign_Exp],0
xor eax,eax
lodsb
cmp al,'+'
jne @f
lodsb
@@:
cmp al,'-'
jne @f
inc [Data_Sign_Exp]
lodsb
@@:
xor ebx,ebx
.cycle0:
cmp al,0
je .cycle0end
cmp al,9
je .cycle0end
cmp al,10
je .cycle0end
cmp al,13
je .cycle0end
cmp al,' '
je .cycle0end
cmp al,'0'
jb .Error
cmp al,'9'
ja .Error
imul ebx,10
and eax,15 ;ᨬ¢®«ë 0-9 ¯¥à¥¢®¤¨¬ ¢ ç¨á«®
add ebx,eax
lodsb
jmp .cycle0
.cycle0end:
cmp [Data_Sign_Exp],0
je @f
neg ebx
@@:
cmp [Data_Flag],0 ;â®çª  ­¥ ¢áâà¥ç « áì?
jne @f
dec edx
@@:
add edx,ebx
xor eax,eax
jmp @f
.Error:
xor eax,eax
inc eax
@@:
ret
endp
align 4
proc str_cat uses eax ecx edi esi, str1:dword, str2:dword
mov esi,dword[str2]