Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FloatToStr proc
- Ten equ -2
- T equ -4
- push ax
- push cx
- push dx
- push bp
- mov bp, sp
- push 10
- push 0
- ;ST(0) = 12.345
- fld1 ;1 12.345
- fld st(1) ;12.345 1 12.345
- fprem ;0.345 1 12.345
- fsub st(2), st ;ST(2) - целая часть
- fxch st(2) ;12 1 0.345
- ;целая часть
- xor cx, cx
- IntPart:
- fidiv word ptr [bp + Ten] ;1.2 1 0.345
- fxch st(1) ;1 1.2 0.345
- fld st(1) ;1.2 1 1.2 0.345 ...
- fprem ;0.2 1 1.2 0.345
- fsub st(2), st ;0.2 1 1 0.345
- fimul word ptr [bp + Ten] ;2 1 1 0.345
- fistp word ptr [bp + T] ;1 1 0.345
- inc cx
- push word ptr [bp + T]
- fxch st(1) ;1 1 0.345 ...
- ftst
- fstsw ax
- sahf
- jnz IntPart
- StoreInt:
- pop ax
- add al, '0'
- stosb
- loop StoreInt ; 0 1 0.345
- ;дробная часть
- fstp st(0) ; 1 0.345
- fxch st(1) ; 0.345 1
- ftst
- fstsw ax
- sahf
- jz exit
- mov al, '.'
- stosb
- mov cx, 20
- FractPart:
- fimul word ptr [bp + Ten] ; 3.45 1
- fxch st(1) ; 1 3.45
- fld st(1) ; 3.45 1 3.45
- fprem ; 0.45 1 3.45
- fsub st(2), st ; 0.45 1 3
- fxch st(2) ; 3 1 0.45
- fistp word ptr [bp + T] ; 1 0.45
- mov dl, [bp - 4]
- add dl, 30h
- mov al, dl
- stosb
- fxch st(1) ; 0.45 1
- ftst
- fstsw ax
- sahf
- loopnz FractPart ; 0 1 ...
- mov al, '$'
- stosb
- exit: fstp st(0)
- fstp st(0)
- add sp,4
- pop bp
- pop dx
- pop cx
- pop ax
- ret
- FloatToStr endp
Add Comment
Please, Sign In to add comment