FIST
으로 결과의 정수 부분을 분리 할 수 있습니다. SASM에는 PRINT_FLOAT 매크로가 없으므로 결과의 소수 부분을 ASCIIZ 문자열로 변환해야합니다. 소수 부분에 10을 곱하여 숫자를 분리하여 관리 할 수 있습니다. 결과 정수는 다음 10 진수입니다. FIST
은 현재 반올림 모드에 따라 정수를 반올림하기 때문에 반올림 모드에주의하십시오! 후속 FISUB
은 음수가 아니어야합니다.
나의 제안 :
이
%include "io.inc"
section .data
val: dq 123.45
ten: dd 10
section .bss
leftdigits: resd 1
rightdigits: resb 100
temp: resd 1
control_word: resw 1
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
;write your code here
fld qword[val]
fsqrt
; modifying rounding mode
fstcw [control_word]
mov ax, [control_word]
or ah, 0b00001100 ; rounding mode: truncating
mov [temp], ax
fldcw [temp] ; load new rounding mode
fist dword [leftdigits] ; store integer part
fisub dword [leftdigits] ; clear integer part
; load 10 and move it to st(1)
fild dword [ten]
fxch
; isolate digits of fractional part and store ASCII
mov edi, rightdigits ; pointer to ASCIIZ-buffer
.get_fractional:
fmul st0, st1 ; one decimal digit into integer
fist dword [temp] ; store digit
fisub dword [temp] ; clear integer part
mov al, byte [temp] ; load digit
or al, 0x30 ; to ASCII
mov byte [edi], al ; store to 'rightdigits'
add edi, 1 ; increment pointer to string
fxam ; st0 == 0.0?
fstsw ax
fwait
sahf
jnz .get_fractional ; no: once more
mov byte [edi], 0 ; null-termination for ASCIIZ
; clean up FPU
ffree st0 ; empty st(0)
ffree st1 ; empty st(1)
fldcw [control_word] ; restore old rounding mode
PRINT_DEC 4, leftdigits
PRINT_CHAR '.' ; decimal point
PRINT_STRING rightdigits
xor eax, eax
ret
를 닮아 코드 : http://en.wikibooks.org/wiki/X86_Assembly/Floating_Point 네,하지만 부동 소수점 숫자를 displaay하는 방법이 표시되지 않았습니다 – SSpoke
플로이드 번호를 표시하는 방법을 알려주세요. – Junaid
어떤 OS를 타겟팅하는지 전혀 알 수 없습니다. – Michael