Using MASM 6.14 .
I needed to do some floating-point calculations so I read up on
the coprocessor instruction format.
It is indeed a nice format and quite straight forward.

In the process of my work I need to print out the floating point
numbers and being lazy I located the calculator written in
assembler for Win32 and used its routine for converting from
float to ASCII.

To use it essentially all one has to do is to be sure that the
number you want to convert it is at the top of the coprocessor
stack when it is called. The routine pops that from the stack in
its processing.

In my work I occasionally want to look at a result in the middle
of processing and so I used the routine referred to above.
However what I am doing may require leaving the value on the top of the stack that the conversion routine pops. NOw I
could easily in my code restore that value after the call to the
printing routine but being lazy I thought I would embed the
conversion routine in a MACRO and have that save and
restore the value at the top of the stack. Since the routine
does a lot of pushing onto the stack I coujld not used any of
the st(x) registers to save the value in so I created an
appropriate memory variable to save it in and restore it from.
However it does not weem to work correctly.

What I do is at the top of the macro, before calling the
conversion routine save the top of the stack to that variable
and at the end load it back to the top of the stack.
Seems to me it should work but it does not.

Are there any problems with Macros and the coprocessor?
Posted on 2001-12-31 21:07:02 by nolpak
Could store the value on the stack (esp):
sub esp,8

fst REAL8 PTR [esp]

;...do stuff...

fld REAL8 [esp]
add esp,8
Do the same for whatever you need to save.
Posted on 2001-12-31 21:37:20 by bitRAKE
Thanks for the suggestion but alas it is of limited use.
When I call the macro to print the float twice in
succession, it works, but if I call it repeatedly in a loop
it does not.

So far the only thing which does consistentlyh work
is to reload the top of the stack after using the Print
Macro.
Posted on 2002-01-01 12:29:23 by nolpak
1-3-2002
I have been playing around trying to get the macro
to save and restore the top of math processor stack and have fif
finally got it to work.

I use a memory variable to save the value with
fst StackTop (name of memory variable) before going
into the body of the macro.
Then at the end, before calling fld I call finit, which resets
the processor
finit
fld StackTop

and this works well.

Using finit does not make the procedure of saving onthe
system stack work however.
Posted on 2002-01-03 15:42:08 by nolpak
That is odd? Can you post or email me the code section you speak of? If one works the other should. You shouldn't have to finit? Maybe the process the shows the value of the top of the FPU stack changes the stack pointer? This should be fixed, if it does. Sorry, I'm at a loss without see the code.
Posted on 2002-01-03 20:40:07 by bitRAKE