I'm trying to use the FCOS instruction in HLA. I

I understand FCOS pops the stack, calculates the cosine of the value and pushes the result back on the stack.

So far I have tried declaring a floating point unit:

To test whether it is working, I tried to take the cosine of r32, and output the result with stdout.put. If correct, the output should be equal to 1. However I'm unsure how to use the FCOS instruction. I've tried moving r32 into one of the 32 bit registers, pushing it onto the stack myself, then writing the instruction:

Then popping the stack, moving the value back to r32 and outputting the value.

I will also be using FSIN but no doubt, once I find out how to use FCOS, I will have no problems with FSIN.

**have**searched but all of the previous topics have been in MASM or some other assembly language.I understand FCOS pops the stack, calculates the cosine of the value and pushes the result back on the stack.

So far I have tried declaring a floating point unit:

`static`

r32 : real32 := 0;

To test whether it is working, I tried to take the cosine of r32, and output the result with stdout.put. If correct, the output should be equal to 1. However I'm unsure how to use the FCOS instruction. I've tried moving r32 into one of the 32 bit registers, pushing it onto the stack myself, then writing the instruction:

`FCOS ();`

Then popping the stack, moving the value back to r32 and outputting the value.

I will also be using FSIN but no doubt, once I find out how to use FCOS, I will have no problems with FSIN.

I have absolutely no experience working with HLA but from programming in Assembly, I can tell you that FPU registers are 80-bits long and their values don't fit in General Purpose Registers that are 32-bits in IA-32 unless you save the contents of the TOS (Top of the FPU Stack) into a DWORD memory pointer as an integral value.

Although the FPU works internally with 80-bit floats, it can work with 32-bit floats (REAL4), 64-bit floats (REAL8), or 80-bit floats (REAL10) to and from memory. All three formats are standard IEEE compliant.

Slugsnack: You may be able to learn how to use the FPU within HLA from AoA (Art of Assembly) from the same author who developed HLA. Although the following tutorial is geared to MASM, you may also acquire some useful FPU knowledge from it:

http://www.ray.masmcode.com/fpu.html

Slugsnack: You may be able to learn how to use the FPU within HLA from AoA (Art of Assembly) from the same author who developed HLA. Although the following tutorial is geared to MASM, you may also acquire some useful FPU knowledge from it:

http://www.ray.masmcode.com/fpu.html

Thanks a lot, both of you.

I figured it out eventually after doing a little more reading in AoA (I am ploughing through the whole thing and hadn't got to the FPU instruction set part yet).

I hadn't realised that the float uses a different stack to the normal registers. Here's the code I tested that works:

//edit :

Now I'm working on converting degrees to radians. To do this, I need to divide by 360 then multiply by 2 pi. I'm really uncomfortable with using FPU instructions. This is what I have so far:

If anyone could point me in the right direction, that'd be great.

//edit :

Sorted ! This is the new code:

//edit :

All is going well now ! Was just wondering though whether there is a floating point square instruction. I'm doing two FPU stack pushes then FMUL but if there was some sort of instruction to do that in one go, it'd make my code easier on the eyes :p

I figured it out eventually after doing a little more reading in AoA (I am ploughing through the whole thing and hadn't got to the FPU instruction set part yet).

I hadn't realised that the float uses a different stack to the normal registers. Here's the code I tested that works:

`Program Distance;`

#include( "stdlib.hhf" )

static

i32 : real32 := 1.570796327;

Begin Distance;

fld(i32);

fcos;

fstp(i32);

stdout.put(i32,nl);

End Distance;

//edit :

Now I'm working on converting degrees to radians. To do this, I need to divide by 360 then multiply by 2 pi. I'm really uncomfortable with using FPU instructions. This is what I have so far:

`Program Distance;`

#include( "stdlib.hhf" )

static

i32 : real32;

Begin Distance;

stdout.put("Input value of theta:",nl);

stdin.get(i32);

fld(i32);

fld(2.0);

fldpi();

fmul();

fld(360.0);

fdiv();

fstp(i32);

stdout.put(i32);

End Distance;

If anyone could point me in the right direction, that'd be great.

//edit :

Sorted ! This is the new code:

`Program Distance;`

#include( "stdlib.hhf" )

static

i32 : real32;

Begin Distance;

stdout.put("Input value of theta:",nl);

stdin.get(i32);

fld(i32);

fldpi();

fmul();

fld(180.0);

fdiv();

fstp(i32);

stdout.put(i32);

End Distance;

//edit :

All is going well now ! Was just wondering though whether there is a floating point square instruction. I'm doing two FPU stack pushes then FMUL but if there was some sort of instruction to do that in one go, it'd make my code easier on the eyes :p

The MASM syntax to square a value which is already in the FPU's top register is as simple as:

fmul st,st

Those are some of the "tricks" which you may find in the suggested tutorial.

fmul st,st

Those are some of the "tricks" which you may find in the suggested tutorial.

Hmm yeah I asked because I was curious as to how you would do a FPU to the power of a non-integer. As far as I know, the only way that can be done is with FSQRT instruction but that is only power half. What would you do if you had to do x^(3/4) for example ? I can think of a few algorithms that would diverge to the correct value. I'm purely curious now :p I just finished my physics app last night.

Could I ask something completely off topic here? Whats' with the blue font color? :lol:

What blue font color?

Means I can pick out my own posts easier and contrasts other people's post's colour making it easier on my eyes to tell who's post it is. Not so much of a problem here but I got used to it. And I like to spice up the screen by making it colourful !

how you would do a FPU to the power of a non-integer

You can find a relatively good description of how to compute any power in Chapter 11 of the tutorial:

http://www.ray.masmcode.com/tutorial/fpuchap11.htm

As you will see, it's not a "simple" procedure.