0

Im trying to create a small program where it asks for a number (radius) and then calculates the area of a circle. BUT when I square the input and multiply it by pi, i get a whole number. I need it in decimal. Could someone explain? Thanks.

TITLE Area of Circle					(main.asm)

; Find Area of Circle: Area = pi * r2
; 
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "Enter radius: ",0dh,0ah,0
pi DWORD 3.14

.code
main PROC
	
	mov edx, OFFSET myMessage ; ask user for input
	call WriteString
	
	call Readdec
	
	
	imul eax, eax	
	imul eax, pi	
	call Writedec
	call Crlf
	
	exit
main ENDP

END main
2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by davio1
0

You can only use the conventional registers for whole numbers.
If you need to program with floating points, you will need to work with the FPU-engine, which has seperate registers and instructions (many info is available online, look for 80x87 FPU).

The solution is then:

...
pi real4 3.14159265
temp real4 ?

...

mov temp,eax
fild temp
fmul st0, st0
fmul st0, pi
fstp temp
mov eax,temp
call Writedec
call Crlf
...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.