English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 27 July 2010, 04:17   #1
sheryn88
 
Posts: n/a
Smile Help needed!!Random octal numbers generator(asm)

I need help in displaying a random 8 digit octal number on the seven segments using 68k assembly language.
I'm designing a software of reaction timer but the first problem come to me is in generating random octal number.
Your help is highly appreciated.
 
Old 27 July 2010, 13:41   #2
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
Do you mean that you want to generate 8 random digits of base 8?

Code:
Randomize   lea         State(pc), a0
            lea         Digits(pc), a1
            move.l      (a0), d0
            moveq       #8-1, d2

loop        ; generate a random value

            move.l      d0, d1
            lsl.l       #2, d1
            eor.l       d1, d0
            move.l      d0, d1
            lsr.l       #7, d1
            eor.l       d1, d0
            move.l      d0, d1
            lsl.l       #7, d1
            eor.l       d1, d0

            ; extract a base 8 digit and store as one byte

            moveq       #7, d1
            and.b       d0, d1
            move.b      d1, (a1, d2.w)
            
            dbf         d2, loop

            move.l      d0, (a0)
            rts

            ; initialize this 32-bit value to non 0 when program starts

State       ds.l        1

            ; Digits will contain 8 bytes, each being a number from 0 to 7

Digits      ds.b        8

Last edited by Leffmann; 27 July 2010 at 13:48.
Leffmann is offline  
Old 27 July 2010, 22:12   #3
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 44
Posts: 3,204
Quote:
Originally Posted by sheryn88 View Post
I need help in displaying a random 8 digit octal number on the seven segments using 68k assembly language.
I'm designing a software of reaction timer but the first problem come to me is in generating random octal number.
Your help is highly appreciated.
You can try this code. It's by no means the best, but it's simple and it should work nicely.
Code:
start
	bsr	rng
	rts
	
rng
	lea	digits,a0
	move.l	#$11111111,d0
	move.l	state,d1
	moveq	#0,d2
	moveq	#7,d6

	moveq	#7-1,d7		;Number of digits-1.
.loop
	add.l	d0,d2
	rol.l	#7,d1
	add.l	d2,d1

	move.l	d1,d3
	and.l	d6,d3		;Need ascii? Add ascii value of "0" to d3.
	move.b	d3,(a0)+
.next
	dbra	d7,.loop
	
	move.l	d1,state
	rts

state
	dc.l	$52896594	;Seed value. Set to anything.
digits
	dc.b	7
	even
Quote:
Originally Posted by Leffmann View Post
Code:
            move.l      d0, d1
            lsl.l       #2, d1
            eor.l       d1, d0
            move.l      d0, d1
            lsr.l       #7, d1
            eor.l       d1, d0
            move.l      d0, d1
            lsl.l       #7, d1
            eor.l       d1, d0
You may want to look at your shift values, they don't seem to be chosen well. I've tested it by plotting points based on x,y cords obtained from this generator, and it's patterned.
Thorham is offline  
Old 28 July 2010, 00:06   #4
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
Hm I did the same test just now and it looks perfectly uniform, and it also passed almost all tests in the Diehard test suite. But let's keep the random-insanity in the other thread, I think sheryn88 was just looking for something simple to test his 7-segment display with.
Leffmann is offline  
Old 29 July 2010, 10:06   #5
sheryn88
 
Posts: n/a
Thanks!!! But i found that the random numbers generated are actually uniform. The group of numbers generated each time i run the program are actually the same. Is it ought to be uniform like this?
 
Old 29 July 2010, 18:39   #6
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 44
Posts: 3,204
Quote:
Originally Posted by sheryn88 View Post
Thanks!!! But i found that the random numbers generated are actually uniform. The group of numbers generated each time i run the program are actually the same. Is it ought to be uniform like this?
It's supposed to be like this. Each time you run the program it starts with the same state or seed, and therefore the numbers will be the same each time, but it's quite simple to fix:
Code:
start
	bsr	randomize
	bsr	rng
	rts

randomize
	lea	$bfe001,a0

	add.b	$400(a0),d0
	lsl.l	#4,d0
	add.b	$500(a0),d0
	lsl.l	#4,d0
	add.b	$600(a0),d0
	lsl.l	#4,d0
	add.b	$700(a0),d0
	move.l	d0,state
	
	rts
	
rng
	lea	digits,a0
	move.l	#$11111111,d0
	move.l	state,d1
	moveq	#0,d2
	moveq	#7,d6

	moveq	#7-1,d7		;Number of digits-1.
.loop
	add.l	d0,d2
	rol.l	#7,d1
	add.l	d2,d1

	move.l	d1,d3
	and.l	d6,d3		;Need ascii? Add ascii value of "0" to d3.
	move.b	d3,(a0)+
.next
	dbra	d7,.loop
	
	move.l	d1,state
	rts

state
	dc.l	0
digits
	dc.b	7
	even
I've added a seed randomizing routine to the code, and it should now produce new numbers each time the program is run (although the seeding algorithm probably isn't the best).
Thorham is offline  
Old 01 August 2010, 08:19   #7
sheryn88
 
Posts: n/a
Thanks a lot for the help!!!
 
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
random number generation (in asm) meynaf Coders. General 183 29 November 2010 20:48
retro sound generator gimbal Retrogaming General Discussion 1 30 September 2008 08:45
landscape generator twizzle MarketPlace 0 04 May 2006 23:47
Landscape generator DDNI request.Apps 30 04 May 2006 19:18
A nice quick small random numbers routine? Photon Coders. General 2 20 December 2004 22:56

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:14.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.06691 seconds with 13 queries