圆锥体积未返回正确值

Volume of cone not returning correct value

我的代码组装正确,但它没有返回圆锥体的体积。我尝试了其他几种方法来得到圆锥体的体积,但没有给出正确答案。有什么我想念的吗?

编辑:我修正了我的代码以输出一个数字,但是它没有给我正确的数字。

这是我用于此代码的公式: V= (22)(r)(r)(h)/21

diviser         DWORD       21
height          WORD        0
radius          BYTE        0                                           ;*** Declare an unsigned, integer variable for the value
product         WORD        0
askRadius       BYTE        "What is the radius?", 0ah, 0dh, 0              ;*** Declare the prompt and message parts
askHeight       BYTE        "What is the height? ", 0
volumeOutput    BYTE        "The volume of the cone is:  ", 0   
lineBreak       BYTE        " ",0dh, 0ah, 0

.code
main PROC

mov ebx, diviser                         ;Initializes the diviser

mov edx,OFFSET askRadius                 ;Asks for Radius
call WriteString
call ReadDec
mov radius, al                           ;moves radius into al (8-bit)
mul radius                               ;Multiplies radius * radius(16-bit)

mov edx,OFFSET askHeight                 ;asks for Height
call writestring
call ReadDec
mov height, dx                           ;moves height into AX
mov WORD PTR product, ax                 ;convert 16-bit into 32-bit
mov WORD PTR product+2, dx               ;converts 16-bit into 32-bit
mul eax                                  ;multiplies by 22
mov edx, 22                              
mul edx
div ebx                                  ;divides by 21

mov edx, OFFSET volumeOutput             
call WriteString
call WriteDec
call WaitMsg
exit

主要结束 结束主要

像这样的东西应该效果更好。请注意,您应该选择要将计算扩展到 64 位的位置。

askRadius       BYTE        "What is the radius?", 0ah, 0dh, 0              ;*** Declare the prompt and message parts
askHeight       BYTE        "What is the height? ", 0
volumeOutput    BYTE        "The volume of the cone is:  ", 0   
lineBreak       BYTE        " ",0dh, 0ah, 0

.code
main PROC

mov edx,OFFSET askRadius                 ;Asks for Radius
call WriteString
call ReadDec
imul eax, eax                            ; radius * radius
mov ecx, eax                             ; save for later

mov edx,OFFSET askHeight                 ;asks for Height
call writestring
call ReadDec
imul eax, eax, 22
mul ecx                                  ;multiplies by radius * radius
mov ecx, 21
div ecx                                  ;divides by 21

mov edx, OFFSET volumeOutput             
call WriteString
call WriteDec
call WaitMsg
exit

main ENDP
END main