アセンブリで簡単な電卓を作ってみました。私はTASM(学校の方針)を使いました。問題は、FBSTP コマンド (コプロセッサ コマンド) で保存された数値を DT 変数に出力することです。
FBSTP adr - パックド 10 進数 (DT で「adr」に定義) としてスタック (ST (0)) の一番上にある値をアドレス「adr」に格納します。スタック ポインタがデクリメントされます。変換はストア プロセス中に行われます。
プログラムをデバッグしましたが、10 で割ると結果が壊れます。例: 12*1=12。res2 の結果は正しいです。AX に移動した後も正しいですが、10 で割ると DX は 2 ではなく 8 になるため、12 ではなく 18 が出力されます。LE: Word 変数で単純な整数ストアを使用し、それを出力すると、正常に動作します。
ここに私が重要だと思うコードの部分があります:
multiplication:
FINIT
FILD x
FILD y
FMUL
FBSTP res2
FWAIT
MOV ax,WORD PTR res2
call write
jmp_line
jmp exit
write PROC NEAR ;my printing proc moves cursor x spaces and starts writing
from back to front
PUSH DX
PUSH AX
PUSH CX
MOV CX,0
CMP AX, 0;check sign
JNS ok_write
NEG AX ;negate if <0
MOV CX,1 ;used to know if number is negative
ok_write:
printspace ;macro that jumps 5 spaces(maximum number length)
;starts printing the number backwards
print_digit:
inc len
;print each digit
MOV DX,0 ;prepare DX for storing the remeinder
DIV CS:ten ;divide AX by 10 so that the last digit of the number is stored
ADD dl,30h ;transform to ascii
PUSH AX ;save AX
MOV ah,02h
INT 21h ;print last digit
printchar 8 ;put cursor over last printed digit
printchar 8 ;move cursor in front of last printed digit
cmp divi,1 ;
JNE not_div
cmp len,1
JNE not_div
printchar '.'
printchar 8
printchar 8
not_div:
POP AX ;retreive AX
CMP AX,0 ;when AX=0 the number is written
JNE print_digit
;/print each digit
CMP CX,1
JNE end_print
printchar '-'
end_print:
POP CX
POP AX
POP DX
RET
write ENDP
どうもありがとう。