在 (8.8) 格式的带有 Pi (3,1415..) 的 AX 上,MUL 操作如何在 Assembly 中工作?

How would the MUL operation on AX with Pi (3,1415..) in (8.8) format work in Assembly?

我是 Assembly 的新手,正在学习定点算法。

AX是16位寄存器-

 MUL Pi  ; Multiplies EAX with Pi and stores result in EAX
 DIV 256 ; Divides EAX by 256 which equals the necessary right- shift for the 8,8 format

但是我觉得不是这样的

带有字大小操作数的 MUL 指令将 AX 与该操作数相乘,并将其结果放入 DX:AX。如果两个操作数都是 8.8 格式,则结果将是 16.16 格式,整数部分在 DX 中,小数部分在 AX 中。要将其转换为 8.8 格式,您可以像这样获取 DLAH 的内容:

MUL Pi        ; multiple by Pi, leaving the integral part in DX and the fraction in AX
MOV AL, AH    ; move the fractional part into place
MOV AH, DL    ; move the integral part into place

一切都会顺利的。请注意,舍入可能会稍微偏离。您可以这样更正:

MUL Pi        ; multiple by Pi, leaving the integral part in DX and the fraction in AX
ADD AX, 0080h ; apply rounding to AH
ADC DX, 0     ; apply carry if any
MOV AL, AH    ; move the fractional part into place
MOV AH, DL    ; move the integral part into place

这样就根据原则

对结果进行了正确的四舍五入
round(x) = ⌊x + 0.5⌋