需要帮助在x86汇编中使用FPU进行乘法

时间:2016-04-23 21:26:14

标签: assembly ascii x86-64 multiplication fpu

基本上,我想将用户输入的值乘以设定值。代码在一起乘以用户输入时起作用,但是,如果我将'number'预设为一个值(例如:6),它将不会进行乘法并返回0.

_start:   
finit                           ; init. the float stack

output inprompt                 ; get radius number 
input  number, 12               ; get (ascii) value of this number
pushd  NEAR32 PTR number        ; push address of number
call   atofproc                 ; convert ASCII to float in ST

fld    st                       ; value1 in ST and ST(1)

mov number, 6

; If I substitute the line above by the two lines below, it works:
; output inprompt, 0
; input number, 12   

pushd  NEAR32 PTR number        ; push address of number
call   atofproc                 ; convert ASCII to float in ST

fmul                            ; value1*value2 in ST
fst   prod_real                 ; store result


push prod_real                  ; convert the results for printing

lea eax, sum_out                ; get the ASCII string address
push eax
call ftoaproc

output outprompt

1 个答案:

答案 0 :(得分:1)

您正在尝试将6从ASCII转换为浮点数,而6是ASCII中的不可打印字符,因此无法将其转换为浮点数。您需要将6更改为54,这是字符'6'的ASCII表示形式。或者,如果您愿意,可以传递浮点常数6.0并删除对atofproc的调用。