До Нового Года вернулся к старой задаче, вышел неоптимизированный код
org 100h; Flat Assembler
use16
FSTCW [SAVE_CW] ;save current FPU control word
MOV AX, WORD [SAVE_CW];retrieve control word
OR AX, 0C00h ;rounding control field = truncate
MOV WORD [NEW_CW], AX ;new FPU control word
FLDCW [NEW_CW] ;load new FPU control word
;FLDCW [SAVE_CW] ;restore original control word
fldpi
; fimul word[cs:n10]
; fimul word[cs:n10]
fchs
;go
mov di,num
fst dword [bp]
mov ecx,[bp]
add ecx,ecx
jnc nominus
mov al,"-"
stosb
fchs
nominus:
; fst dword[bp] ;whole number
fist dword[bp+8];integer part
;fld dword[bp] ;N
fisub dword[bp+8];N-[N]
fstp dword[bp];fractional part
;integer
mov cx,di;keep position
fild dword[bp+8]
ii: fidiv word[cs:n10]
fistp dword[bp+16];[N/10]
fild dword[bp+16];[N/10]
fimul word [cs:n10];*10
fisub dword [bp+8]
fchs
fistp dword[bp+16]
fild dword[bp+8]
fidiv word[cs:n10]
fist dword[bp+8]
xor ax,ax
ftst
fstsw ax;c3=1
sahf
jz exintlp
mov eax,dword[bp+16]
add al,$30
stosb
jmp ii
exintlp:
;mirror number
mov si,cx
push di
dec di
sub cx,di
neg cx
shr cx,1
je exmirror
emlp:
mov al,byte[ds:si]
mov ah,byte[ds:di]
mov byte[ds:di],al
mov byte[ds:si],ah
inc si
dec di
loop emlp
exmirror:
pop di
;float
mov al,"."
stosb
fld dword[bp]
kk: fimul word[cs:n10]
fist dword [bp+8];fisttp
mov eax,dword[bp+8]
fisub dword [bp+8]
fst dword[bp]
add al,$30
stosb
xor ax,ax
ftst
fstsw ax;c3=1
sahf
jnz kk
;tail
mov al,"$"
stosb
push cs
pop ds
mov dx,num
mov ah,9
int 21h
ret
NEW_CW: dw 0
SAVE_CW: dw 0
n10:dw 10
num:
use16
FSTCW [SAVE_CW] ;save current FPU control word
MOV AX, WORD [SAVE_CW];retrieve control word
OR AX, 0C00h ;rounding control field = truncate
MOV WORD [NEW_CW], AX ;new FPU control word
FLDCW [NEW_CW] ;load new FPU control word
;FLDCW [SAVE_CW] ;restore original control word
fldpi
; fimul word[cs:n10]
; fimul word[cs:n10]
fchs
;go
mov di,num
fst dword [bp]
mov ecx,[bp]
add ecx,ecx
jnc nominus
mov al,"-"
stosb
fchs
nominus:
; fst dword[bp] ;whole number
fist dword[bp+8];integer part
;fld dword[bp] ;N
fisub dword[bp+8];N-[N]
fstp dword[bp];fractional part
;integer
mov cx,di;keep position
fild dword[bp+8]
ii: fidiv word[cs:n10]
fistp dword[bp+16];[N/10]
fild dword[bp+16];[N/10]
fimul word [cs:n10];*10
fisub dword [bp+8]
fchs
fistp dword[bp+16]
fild dword[bp+8]
fidiv word[cs:n10]
fist dword[bp+8]
xor ax,ax
ftst
fstsw ax;c3=1
sahf
jz exintlp
mov eax,dword[bp+16]
add al,$30
stosb
jmp ii
exintlp:
;mirror number
mov si,cx
push di
dec di
sub cx,di
neg cx
shr cx,1
je exmirror
emlp:
mov al,byte[ds:si]
mov ah,byte[ds:di]
mov byte[ds:di],al
mov byte[ds:si],ah
inc si
dec di
loop emlp
exmirror:
pop di
;float
mov al,"."
stosb
fld dword[bp]
kk: fimul word[cs:n10]
fist dword [bp+8];fisttp
mov eax,dword[bp+8]
fisub dword [bp+8]
fst dword[bp]
add al,$30
stosb
xor ax,ax
ftst
fstsw ax;c3=1
sahf
jnz kk
;tail
mov al,"$"
stosb
push cs
pop ds
mov dx,num
mov ah,9
int 21h
ret
NEW_CW: dw 0
SAVE_CW: dw 0
n10:dw 10
num:
Комментарии
Отправить комментарий