27 July 2010, 04:17  #1 
Posts: n/a

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. 
27 July 2010, 13:41  #2 
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 #81, 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 32bit 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. 
27 July 2010, 22:12  #3  
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 44
Posts: 3,204

Quote:
Code:
start bsr rng rts rng lea digits,a0 move.l #$11111111,d0 move.l state,d1 moveq #0,d2 moveq #7,d6 moveq #71,d7 ;Number of digits1. .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 

28 July 2010, 00:06  #4 
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 randominsanity in the other thread, I think sheryn88 was just looking for something simple to test his 7segment display with.

29 July 2010, 10:06  #5 
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?

29 July 2010, 18:39  #6  
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 44
Posts: 3,204

Quote:
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 #71,d7 ;Number of digits1. .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 

01 August 2010, 08:19  #7 
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 

