Back | Reverse | Quick Reply | Post Reply |

Need a bit of help with ASM?
Link | by hello on 2009-11-08 18:32:18
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.

No.

Re: Need a bit of help with ASM?
Link | by gendou 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?
Link | by hello on 2009-11-11 21:08:53
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.

No.

Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2024 Gendou | Terms of Use | Page loaded in 0.0024 seconds at 2024-12-30 11:26:17