2012-03-07 110 views
0

工作的浮点堆栈上做操作:NASM浮点错误

fld  qword [perResult]  ;load st0 with perimeter 
fsub qword [firstSide]  ;take st0 and minus firstSide, st0= perimeter - firstSide 
fmul qword [perResult]  ;take st0 and multiply by perimeter, st0 = difference of first equation * perimeter 
fstp qword [res1]   ;take the result off of st0 and place them into variable equation1 

;setting up to take perimeter minus second side 
fld  qword [perResult]  ;load up perimeter into st0 
fsub qword [secondSide]  ;take st0 and minus secondSide, st0 = perimeter - secondSide 
fstp qword [eq2] 

出于某种原因,如果我注释掉方程得到eq2,我会得到前面的公式在正确的输出以获得res1

,但是如果我离开方程式2注释掉我会得到一个0作为输出

并为下一个公式一样的东西,由于某种原因,它的归零出来,如果有日以后的功能以前。

有人曾经遇到过这个问题吗?

这里是打印功能

mov rdi, areaMsg  
call print_string 
xor r14,r14 
movsd xmm0, [eq2] ;move sumResult into xmm0 for printing 
mov qword rax, 1 
mov r14, [eq2] ;move result into r14 register for printing float 
call print_float 
call print_nl 
jmp Decision 

回答

0

我看到上面的代码没有问题。我编译并在Windows XP下运行:

bits 16 
org 0x100 

fld  qword [perResult]  ;load st0 with perimeter 
fsub qword [firstSide]  ;take st0 and minus firstSide, st0= perimeter - firstSide 
fmul qword [perResult]  ;take st0 and multiply by perimeter, st0 = difference of first equation * perimeter 
fstp qword [res1]   ;take the result off of st0 and place them into variable equation1 

;setting up to take perimeter minus second side 
fld  qword [perResult]  ;load up perimeter into st0 
fsub qword [secondSide]  ;take st0 and minus secondSide, st0 = perimeter - secondSide 
fstp qword [eq2] 

ret 

align 8 

perResult  dq 11.0 
firstSide  dq 1.0 
res1   dq 0.0 ; (perResult - firstSide) * perResult = (11-1)*11 = 110 
secondSide  dq 2.0 
eq2    dq 0.0 ; perResult - secondSide = 11-2 = 9 

并正确计算110和9(在调试器中检查)。

如果出现问题,它代码中没有显示。

+0

好吧,哼,那它一定是我打印的方式, – user1050632 2012-03-07 02:01:52