Hello, Everyone!

I'm new to here and new to assembly and I had a couple of questions about floating point.  My teacher asked us to write a bubblesort code using REALS, my questions are:

1) Is there such thing as an array of floating point values?
2) do i load the FPU value onto the stack before comparing?

Thanks,
-Flip
Posted on 2010-07-23 04:00:36 by l flipboi l
1) Is there such thing as an array of floating point values?
2) do i load the FPU value onto the stack before comparing?


1. Yes. The most common data types are called REAL4 and REAL8 (equivalent to FLOAT and DOUBLE in C). These are 32bits and 64bits in size respectively, so an array of them is similar to an array of DWORD (or QWORD).

2. Yes. You will have to load at least ONE of the two values being compared onto the FPU stack. You may load both, and in this case it's worth noting that the two values being compared can be at any position in the FPU stack - they don't need to appear in sequence.

Posted on 2010-07-23 07:37:36 by Homer
Thanks, How do I access different parts of that array....

for example in C++ i have

int Array = {1,2,3,4,5}

what would be the command to load the value of, let's say 4?

what is the equivalent statement of

Array[3]...
Posted on 2010-07-23 18:57:47 by l flipboi l
To define an array of REAL4 or REAL8 as Global data (MASM assembler):

MyArray1 REAL4 16 dup (0.0f) ;<-- defines an array of 16 floats, all preset to zero
MyArray2 REAL4 1.0f, 2.0f, 3.0f,4.0f,0005.000000f ;<--- defines array of five initialized floats


And to define an array as a Procedural Local Variable ("stack local"):
LOCAL MyArray[16]:REAL4  ;16 unitialized floats


That last one looks deceptively like C - however, we reference elements of arrays in ASM quite differently to C.
You'll be learning about a couple of different "Addressing Modes" in the next day or two :)
Posted on 2010-07-23 20:24:29 by Homer
Thanks, Homer!

Also, you mentioned how you can compare different stack positions....whats the syntax for that?

The only one i'm able to find in the book is FCOM...but I want to compare ST(1) to ST(2)
Posted on 2010-07-23 20:25:43 by l flipboi l
And that's all one needs. Actually it compares st0 with st1.
Posted on 2010-07-24 11:09:01 by ti_mo_n
I was not clear enough about stack compares...
You can compare any fpustack position with st(0).

Example:
fcom st(7)  ; compare st(0) to st(7) ... st(0) is implicit in this case.

Posted on 2010-07-24 20:42:42 by Homer
Np, Homer.  Thanks!
Posted on 2010-07-25 01:07:34 by l flipboi l
Actually, you don't need the FPU to compare REALs once you know their format and you know what you are doing. You can compare them as if they were integers with one minor difference.

- When both are positive, the comparison result is the same as if they were integers.
- When one is positive and the other negative, the positive one will always be "greater".
- When both are negative, the "greater" one will be the more negative one. This is the only difference from comparing regular integers.

If you are interested in learning some more about the format of REALs, try:
http://www.ray.masmcode.com/tutorial/fpuchap2.htm#floats

Your teacher is probably expecting everyone to be using the FPU. He may, or may not, be aware that it can be done otherwise. Your classmates may also learn something else in the process.
Posted on 2010-07-25 23:40:50 by Raymond
Hey, Thanks!

We have a new teacher and this is his first time teaching this class.  I'm pretty sure he'll probably mention that later on, but right now he wants to hammer us down on learning FPU stacks.  I gotta admit, ASM is pretty hard stuff to learn.
Posted on 2010-07-26 03:04:01 by l flipboi l