-2

重複の可能性:
x86-64 アセンブリによる高調波系列

アセンブリで高調波級数のバージョンを実行しようとしています

現在のコードは、合計される値が入力された値よりも大きくなるまで、1 + 1/2 + 1/3 + 1/4 + 1/n かかります。(浮動小数点値)

現在、コードは最初のループの後にループから抜け出し、.33333 を出力します。

それは私の終了条件ですか?

denominator:
xor r14,r14             ;zero out r14 register
add r14, 2              ;start counter at 2
fld1                    ;load 1 into st0
fxch    st2
denomLoop:
fld1
mov [divisor], r14              ;put 1 into st0
fidiv   dword [divisor]         ;divide st0 by r14
inc r14             ;increment r14
fst qword [currentSum]      ;pop current sum value into currentSum
addParts:
fxch    st2             ;put the current value that is in st2 into st0
fadd    qword [currentSum]      ;add result of first division to 1
fxch    st2             ;place result of addition into st2
fld qword [realNumber]          ;place real number into st0
;compare to see if greater than inputed value
fcom    st2             ;compare st0 with st2
fstsw   ax              ;needed to do floating point comparisons on FPU
sahf                    ;needed to do floating point comaprisons on FPU
jae done                ;jump if greater than
jmp denomLoop           ;jump if less than 
4

1 に答える 1

1

この行は疑わしいようです:

fst qword [currentSum]      ;pop current sum value into currentSum

コメントに反してfst、スタックの一番上をポップせずにメモリに格納します。あなたがfstpそれをポップしたいなら、あなたはしたいです。

于 2012-04-05T00:22:02.713 に答える