继续对浮点堆栈进行操作:
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 :(得分: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(在调试器中检查)。
如果出现问题,则代码中没有显示。