PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Small question for ASM gurus!

Hi all,

Me again, I am doing VERY good progress with my dynamic compiler and I've come to a point where I need to pass a DOUBLE type value to a void.

Code:
void test (double d)
{
}

test(10.5)


Now the disassembly of this code would look something like this:

Code:
24: test(10.50);
1A01124A 68 00 00 25 40 push 40250000h
1A01124F 6A 00 push 0
1A011251 E8 B4 FD FF FF call @ILT+5(test) (1a01100a)
1A011256 83 C4 08 add esp,8


How can the values 0x40250000 and 0 be calculated? I am trying to convert this 10.5 double to a (2)4-byte value. How can this be done?

Regards,
Kornalius
Well, since ARM doesn't support floats you gonna have to convert them to some sort of fixed point format.
If you wanted to conver to 16:16 format (4 bytes) then you could do (floatVar*(1<<16)).
Of course, as it is always the case with fixed point, you will have to account for overflow ...

That's asuming I understand your question correctly :-)
Why you would ever want to do double precision floating point artithmetic in ARM escapes me, but heres the jist of it.

That number being pushed onto the stack (in x86 assembly by the way) is an IEEE double precision floating point number.

where the first bit is the sign
the next 11 bits are the exponent (base 2) in excess ((2^10)-1) notation
the remaining 52 bits are the mantisa with an assumed 1 before them

so 40250000 00000000h is really

[0][100 0000 0010][01010.....0] (in binary)

the sign bit is 0 ie. positive
the exponent - ((2^10)-1) is 2^3

the last bits are the exponent
(1).010100000000000000 = 1.3125 * 2^3 = 10.5

so that is how you do it... my suggestion to you is to pick up any computer architecture book and look up the IEEE standard, because there are special representations for infinity, overflows and zero and can probably explain it more concisely then I can.

On arm you would place the lowest 32 bits into r0 and the highest 32 bits into r1, as per the calling convention set out in the docs with VC++ME (those ohh soo minimal docs on arm assembly)
Wow, thanx a lot. The reason why I want to use double is because in my compiler there is no variable types per say. A string can be used in a + operation with a integer etc... So I save all variables and stack operations into a char * and a double value. So mathematics operation are done more efficiently that converting char * into double for every operation. I am also thinking in adding a int value, so that it's faster in most operation. I cannot limit the use to float values.

Btw, is this operation (double -> IEEE (2) 4bytes) conversion easy to do in C?

Regards,
Kornalius.
Hi guys,

Here is what I found and it works quite good:

Code:

#define NINTS 2 /* number of ints in a double */

typedef union {
double f;
unsigned int i[NINTS];
struct {
unsigned int m2 : 32;
unsigned int m : 32;
} ieee;
} ieeefloat;

floattest(double f)
{
ieeefloat d;

d.f = f; // Now d.ieee.m and d.ieee.m2 contains the 2 ieee values that represent the double value.
}


Hope you enjoy!

Regards,
Kornalius