Need a bit of help with ASM?
| |
How do i make my chip 'randomly' generate numbers given these set of instuctions ranging from 1-6? http://talking-electronics.netfirms.com/page-25.html. |
Re: Need a bit of help with ASM?
Link |
by
on 2009-11-08 19:01:00
|
This is the standard C library rand() function, you could implement this in assembly:static unsigned long seed = 1; int rand_r(unsigned long* seed) { unsigned long ulR1 = -*(long*)seed & 0x0000ffff; unsigned long ulR2 = (-*(long*)seed >> 16) & 0x0000ffff; ulR1 *= 642; ulR2 *= 642; ulR2 += ulR1 >> 16; ulR1 = (ulR2 << 16) + (ulR1 & 0x0000ffff); ulR2 >>= 16; ulR2 -= ulR1; *seed = ulR2 + 0x60608420; *seed &= 0x7FFFFFFF; return( *(int*)seed ); } |
Re: Need a bit of help with ASM?
| |
Sad to say, but I am illiterate with C. Hence, I don't understand what '>>' or 'seed' means. Looks like a bit of research is required on my side. Thanks anyways. |