was looking for an asm floating random gen, range between 0.0 and 1.0.
every link, sample is appreciated.
THX B7
every link, sample is appreciated.
THX B7
;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
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
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
thx bitrake, very useful link.
B7
I just overdo with this line:
and eax,0000000000000000000000000001111b
and eax,0000000000000000000000000001111b
Can u tell my why 24th digit of 32 bit floating point have to be 1 ????
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.
[1 sign bit][8 bit exponent] 1. [23 bits fraction]
REAL10's do support denormalized floats.
still dont know why it's there for ??? Can u give it to me more straight ???
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?
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?
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
Can't find any good link to learn it.
B7
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]
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.
http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
[+/-] 1.
1.0 {decimal} = + 1.0 SHL 0 {binary}
[+] [0+127] 1. [0]
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.
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
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
I didn't yet understand, if for 1.0 the 1 is skipped, what's the binary for 0.0 and 0.5 ?
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]
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.
for know, as workaround i've tought this easy random gen....
This is my first sketch, generate 3 dufferents floatings seems work for now.
B7
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
@@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:
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:
10 {decimal} = 1010.0 {binary} = + 1.010 x 2^3
[+] [127+3] 1. [010]
0 10000010 01000000000000000000000 = 41200000h
[+] [127+3] 1. [010]
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.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 ... :)
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 ... :)
1000 {decimal} = 1111101000.0 {binary} = + 1.111101000 x 2^9
[+] [127+9] 1. [111101000]
0 10001000 11110100000000000000000 = 447A0000h
[+] [127+9] 1. [111101000]
0 10001000 11110100000000000000000 = 447A0000h
I looked at the question in a different way. I made a bloated program do the work with a lot of extra steps.
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
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