was looking for an asm floating random gen, range between 0.0 and 1.0.

every link, sample is appreciated.

THX B7
Posted on 2003-06-15 15:47:48 by Bit7
;Dont take it too serious its my first time with floating points :P ;

call Your_random_func ( range as below :P <0 , 10> )
;return eax E <0b , 0000000000000000000000000000001010b>

and eax,0000000000000000000000000001111b
or eax,0000101010000000000000000000000b

mov IntoYourFavoriteFloatingPointVariable32bit,eax

;TO large amount of 000100101b i hope i did not fu**ed something
Posted on 2003-06-15 17:22:57 by AceEmbler
Posted on 2003-06-15 17:41:57 by bitRAKE
thx ace, seems pretty nice soluition, to understand well what you'r doing i'm gonna review what the floating bits mean..
thx bitrake, very useful link.

B7
Posted on 2003-06-16 01:50:52 by Bit7
I just overdo with this line:

and eax,0000000000000000000000000001111b
Posted on 2003-06-16 11:35:15 by AceEmbler
Can u tell my why 24th digit of 32 bit floating point have to be 1 ????
Posted on 2003-06-17 09:15:25 by AceEmbler
REAL4's don't support denormalized floats, so bit 24 is implied though not present. Having bit 24 implied gives an added bit of percision in the limited space of 32-bits.

[1 sign bit][8 bit exponent] 1. [23 bits fraction]

REAL10's do support denormalized floats.
Posted on 2003-06-17 16:08:28 by bitRAKE
still dont know why it's there for ??? Can u give it to me more straight ???
Posted on 2003-06-18 01:34:46 by AceEmbler
If the exponent is all 0s, but the fraction is non-zero (else it would be interpreted as zero), then the value is a denormalized number, which does not have an assumed leading 1 before the binary point. Thus, this represents a number (-1)s x 0.f x 2-126, where s is the sign bit and f is the fraction. For double precision, denormalized numbers are of the form (-1)s x 0.f x 2-1022. From this you can interpret zero as a special type of denormalized number.

http://grouper.ieee.org/groups/754/ <-- they did it - read why.

Maybe I don't understand the question? What bit 24 are you speaking of?
Posted on 2003-06-18 07:17:00 by bitRAKE
while you're talking about bit 24, i'm still trying to understand what decimal 1.0 correspond to single binary, and why.

Can't find any good link to learn it.

B7
Posted on 2003-06-18 07:18:36 by Bit7
Here is a start:
http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html

[+/-] 1.

1.0 {decimal} = + 1.0 SHL 0 {binary}

[+] [0+127] 1. 

0 01111111 00000000000000000000000

*The bold part is implied (bit not present).

Intel Manual Volume One is where I learned from.

The notation is analogous to scientific notation in base ten.

1.5643 x 10^-4

...but in binary...

1.01010001 x 2^-13

1.{fraction} x 2^{exp}

The exponent basically results in a shift of the binary bits - left for positive and right for negitive. The length of the fraction determines the accuracy of the number.
Posted on 2003-06-18 07:45:50 by bitRAKE
many tanks for the links Rake ! :)

Seems good links but sincerly, i didn't understand very much the concept, maybe my technical-english is not so good, maths was not my strong at school :) maybe my head is too hard.

I didn't yet understand, if for 1.0 the 1 is skipped, what's the binary for 0.0 and 0.5 ?

B7
Posted on 2003-06-18 15:51:34 by Bit7

I didn't yet understand, if for 1.0 the 1 is skipped, what's the binary for 0.0 and 0.5 ?
Zero is zero, but can be negitive, too (80000000h) -- isn't there always an exception to rules - this is it. :grin:

0.5 {decimal} = 0.1 {binary}

So, we shift the number left by one to put the one bit out front - we have to do this because it is implied.

0.5 {decimal} = 0.1 {binary} = + 1.0 x 2^-1

[+] [-1+127] 1. 

0 01111110 00000000000000000000000

Bit7, I'll keep converting numbers until you get it - no problem, take your time. Give me a harder one to work through. ;) Don't forget your debugger either - I would be nothing without it - thank you Olly!

All binary numbers (except zero) can be represented as:

+/- 1.{frac} x 2^{exp}

[+/-] [127+exp] 1.
Posted on 2003-06-18 16:36:59 by bitRAKE
for know, as workaround i've tought this easy random gen....

``````

proc		AngeloFloatRandom

LOCAL	s_rf	 :dword
LOCAL	s_i1     :dword

mov	[s_i1], 10
xor	ecx,ecx
lea  	esi, [g_rf1]
@@GetNumber:	mov	eax, [g_seed]
ror	eax, 1
mov	[g_seed], eax
and	eax, 1110b
cmp	eax, 10
jg	@@GetNumber
mov	[s_rf], eax

ffree	st(0)
fild	[s_rf]
fidiv	[s_i1]
fstp	[dword ptr esi]

inc	ecx
add	esi,4
cmp	ecx,3
jne	@@GetNumber

ret

endp		AngeloFloatRandom

``````

This is my first sketch, generate 3 dufferents floatings seems work for now.
B7
Posted on 2003-06-18 17:12:44 by Bit7
@@GetNumber: mov eax,
ror eax, 1
mov , eax
and eax, 1110b
cmp eax, 10
jg @@GetNumber

Thats a LOL part.

I would avoid loops in random generator proc

But maby i'm wrong and my post is LOL :tongue:
Posted on 2003-06-18 17:35:56 by AceEmbler
10 {decimal} = 1010.0 {binary} = + 1.010 x 2^3

[+] [127+3] 1. 

0 10000010 01000000000000000000000 = 41200000h

``````proc		AngeloFloatRandom

LOCAL	s_rf	 :dword
LOCAL	s_i1     :REAL4

mov	DWORD PTR [s_i1], [b]41200000h[/b]
xor	ecx,ecx
lea  	esi, [g_rf1]
@@GetNumber:	mov	eax, [g_seed]
ror	eax, 1
mov	[g_seed], eax
and	eax, 1110b
cmp	eax, 10
jg	@@GetNumber
mov	[s_rf], eax

ffree	st(0)
fild	[s_rf]
[b]fdiv[/b]	[s_i1]
fstp	[dword ptr esi]

inc	ecx
add	esi,4
cmp	ecx,3
jne	@@GetNumber

ret

endp		AngeloFloatRandom``````
:) Faster to work directly with floats.
Posted on 2003-06-18 18:28:36 by bitRAKE
many thanks again bitrake,

Ace, you're agree, that was just a test if it was warking :) Now i will get sure my random is < 10 so no loop will be necessary.
I will also give more precision to my 0.xxx number, i will get from the seed a decimal 1XXX number and then i will divide for 1000.

This until i will understand floating ... :)
Posted on 2003-06-19 01:39:13 by Bit7
1000 {decimal} = 1111101000.0 {binary} = + 1.111101000 x 2^9

[+] [127+9] 1. 

0 10001000 11110100000000000000000 = 447A0000h
Posted on 2003-06-19 09:06:10 by bitRAKE
I looked at the question in a different way. I made a bloated program do the work with a lot of extra steps.
Posted on 2003-06-19 18:46:53 by roaknog
Thanks roak, it's very useful, but i want to understand the conversion....

Hey Professor Bitrake, Let's correct my first test......

+0 could be

+ 127 0
1 01111111 000000000000000000000000

--------------------------------------
+0.232 could be

+ 127-1 232
1 01111110 111010000000000000000000

--------------------------------------
+1.54 could be

+ 127 154 (1 is implied)
1 01111111 001101000000000000000000

--------------------------------------
+2.473 could be

+ 127 2473 (1 is implied)
1 01111111 001101010010000000000000

--------------------------------------
+7854.23

+ 127+12 7854.23 (1 is implied)
1 00001100 111010101110101110000000
Posted on 2003-06-21 09:16:31 by Bit7