您的位置:首页 > 其它

关于罗云彬第7章时钟程序坐标计算的分析

2008-10-03 09:50 507 查看
本来我已进行到第八章,可是有些问题还要向前查找,这一查就发现了很多问题,如第203页程序的子程序计算时钟圆周上某个角度对应的X坐标 X=圆心X+Sin(角度)*半径
_dwPara180 dw 180

_CalcX proc _dwDegree,_dwRadius
local @dwReturn
fild dwCenterX
fild _dwDegree
fldpi
fmul
fild _dwPara180
fdivp st(1),st
fsin
fild _dwRadius
fmul
fadd
fistp @dwReturn
mov eax,@dwReturn
ret
_CalcX endp

发现问题了,现在我把FPR八个通用数据寄存器中的内容演示一下:





从这时算的结果就不一样了fadd的结果是st(0)的内容是dwRadius*sin(PI*_dwDegree/180)+sin(PI*_dwDegree/180),不和书上一样了。
我把书上的程序用OllyDBG编译了一下,结果发现



发灰的地方就是程序_CalcX程序的内容,这和源程序不一样。fmul变成了fmulp st(1),st
fadd变成了faddp st(1),st ,其它都一样。
接着在一本国外的教材上看到了对无参数浮点运算的如下解释:fmul (none) ; pops ST and ST(1), multiplies them and pushes to stack.
fdiv (none) ; pop ST and ST(1), calculates ST(1)/ST pushes quotient onto th estack
fsub (none) ; pops ST and ST(1), calculates ST(1)-ST; and pushes the difference into the stack
fadd (none) ;pops both ST and ST(1), adds these values and pushes the sum onto the stack top
这样来说fadd可以解释为faddp st(1),st
fmul可解释为fmulp st(1),st
这下就全明白了。
所以这段程序栈内的内容可以演示如下:





@dwReturtn中存dwCenterX+_dwRadius*sin(PI*_dwDegree/180)值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: