Learn the most important control and control categories that every architect and developer should include in their projects.

On to the next section: floating point calculation. I'm a bit confused on how to do this. I wanted to find the volume of a sphere. Obviously, it's 3/4 PI r^3. So, I attempted to do this:

EXTRN getfp: NEAR, putfp: NEAR

include mymacros.txt

.MODEL SMALL

.586

.STACK 100h

.DATA

radius dd ?

volume dd 1

.386

.CODE

SPHERE PROC

startup

display "Please enter a radius: "

infp

fld st ; load user input

fmul

fldpi

fmul

fmul

fmul 4

fdiv 3

display "The volume of the sphere is: "

outfp

endup

SPHERE ENDP

END SPHERE

EXTRN getfp: NEAR, putfp: NEAR

include mymacros.txt

.MODEL SMALL

.586

.STACK 100h

.DATA

radius dd ?

volume dd 1

.386

.CODE

SPHERE PROC

startup

display "Please enter a radius: "

infp

fld st ; load user input

fmul

fldpi

fmul

fmul

fmul 4

fdiv 3

display "The volume of the sphere is: "

outfp

endup

SPHERE ENDP

END SPHERE

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EXTRN getfp: NEAR, putfp: NEAR, dec2fp: NEAR, fp2dec: NEAR, bin2dec: NEAR

include mymacros.txt

.MODEL SMALL

.586

.STACK 100h

.DATA

radius dd ?

volume dd 1

four dd 4

three dd 3

.386

.CODE

SPHERE PROC

startup

display "Please enter a radius: "

infp

fld st ; load user input

fmul

fldpi

fmul

fmul

fmul four

fdiv three

display "The volume of the sphere is: "

outfp

endup

SPHERE ENDP

END SPHERE

radius dd ?

four dd 4

three dd 3

.386

.CODE

SPHERE PROC

startup

display "Please enter a radius: "

infp

fstp radius ; load user input

fld radius

fld radius

fmul

fldpi

fmul

fld four

fmul

fld three

fdiv

display "The volume of the sphere is: "

outfp

'fstp' will pop the value of st0 from the "stack".

so, your calculation above is

(radius ^ 2) * pi * 4 / 3

you need another

fld radius

fmul

or use 'fst' instead of 'fstp', and add just another 'fmul'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialfld radius

fld radius

fld radius

fmul ; r^3

fldpi

fmul ; PI(r^3)

fld four

fmul ;4PI(r^3)

fld three

fdiv ;(4/3)PI(r^3)

fst radius ; load user input

fld radius

fld radius

fld radius

fmul ; r^3

fldpi

fmul ; PI(r^3)

fld four

fmul ;4PI(r^3)

fld three

fdiv ;(4/3)PI(r^3)

fstp radius ; load user input

fld radius

fld radius

fmul

fld radius

fmul ; r^3

fldpi

fmul ; PI(r^3)

fld X ; X = 4

fmul ; 4PI(r^3)

fld Y ; Y = 3

fdiv ;(4/3)PI(r^3)

fld 4

and of course, there was an error. Thanks :)

the compiler will generate floating point constants when asked to:

mydword dd 1023 ; DWORD

myqword dq 0 ; QWORD

myfloat dd 1.5 ; low-precision "float" is of a dword size

mydouble dq 3.141592654 ; "double" is qword size

if you want to force a floating point variable with an integer value, use '3.0'.

this, at least, works for NASM...

Assembly

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get this solution by purchasing an Individual license!
Start your 7-day free trial.

error A2001: immediate operand not allowed

It's from these:

fmul 4

fdiv 3