0

致力于对浮点堆栈进行操作:

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,我将得到 a0作为输出

下一个方程也是一样的,如果在前一个方程之后有一个函数,出于某种原因,它会将其归零。

以前有人遇到过这个问题吗?

这是打印功能

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
4

1 回答 1

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(在调试器中检查)。

如果有问题,那是在您没有显示的代码中。

于 2012-03-07T01:42:34.140 回答