[英]Finding the volume of a sphere in irvine assembly
I have been given an assignment in my assembly class to create a simple program to find the volume of a sphere given a users input, I have to display a message followed by the volume with a fractional amount... I have come up with the following code but unfortunately am stumped by where remainders go and as such how to call them. 在装配类中,我得到了一个分配,以创建一个简单的程序来找到给定用户输入的球体的体积,我必须显示一条消息,然后是小数的体积...我想出了后面的代码,但不幸的是,剩下的地方以及如何称呼它们为难。 Anyone have an idea where I'm messing up and how I could fix it?
任何人都知道我要搞砸了,我该如何解决?
INCLUDE Irvine32.inc
.data
radius byte 0
prompt byte "Please enter the radius of the sphere~ ", 0
volumeMessage byte "The volume of the sphere is~ ", 0
period byte ".", 0
volumeNumber dword 0, 0dh,0ah
volumeFraction dword 0, 0dh,0ah
piMul dword 88
piDiv dword 21
.code
main PROC
mov edx, OFFSET prompt
call WriteString
call readdec
mov radius, al
mul radius
mul radius
mul piMul
div piDiv
mov volumeNumber, eax
mov volumeFraction, edx
mov edx, OFFSET volumeMessage
call WriteString
mov edx, OFFSET volumeNumber
call WriteDec
mov edx, OFFSET period
call WriteString
mov edx, OFFSET volumeFraction
call WriteDec
call WaitMsg
exit
main ENDP
END main
From Irvine32.asm: 从Irvine32.asm:
;-----------------------------------------------------
WriteDec PROC
;
; Writes an unsigned 32-bit decimal number to
; the console window. Input parameters: EAX = the
; number to write.
So instead of: 所以代替:
mov edx, OFFSET volumeNumber
call WriteDec
you should use: 您应该使用:
mov eax, volumeNumber
call WriteDec
And similarly for volumeFraction
. 同样适用于
volumeFraction
。
Due to the sloppy code your program can only process radii smaller than 16. 由于代码草率,您的程序只能处理半径小于16的半径。
mov radius, al
mul radius
mul radius
After the first multiplication result is in AX but the second multiplication will only use AL! 在第一个乘法结果在AX中之后,但是第二个乘法将仅使用AL! Since 16*16 is already to large for the AL register you end up with a very limited range of usable numbers.
由于AL寄存器的16 * 16已经很大,因此您得到的可用数字范围非常有限。
Problems continue with the third multiplication. 第三次乘法仍然存在问题。 Here because piMul is defined as dword the
mul
uses EAX but only AX has a definitve value from the previous code. 在这里,因为piMul被定义为dword,所以
mul
使用EAX,但只有AX具有先前代码中的定义值。
mul piMul
You could define radius a dword and write 你可以定义一个半径和一个双字
mov radius, eax
imul eax, radius
imul eax, radius
mul piMul
div piDiv
Furthermore as Michael said WriteDec expects the number itself and not the address to the number. 此外,正如Michael所说, WriteDec期望数字本身而不是数字的地址。 So drop the OFFSET tag.
因此,删除OFFSET标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.