Random Halfword Generator PPC ASM - Printable Version +- Mario Kart Wii Gecko Codes, Cheats, & Hacks (https://mariokartwii.com) +-- Forum: Hacks/Modding (https://mariokartwii.com/forumdisplay.php?fid=14) +--- Forum: Coding & Hacking General Discussion (https://mariokartwii.com/forumdisplay.php?fid=23) +--- Thread: Random Halfword Generator PPC ASM (/showthread.php?tid=1341) |
Random Halfword Generator PPC ASM - Vega - 11-08-2019 This is my attempt of writing the Middle Square Theorem (using the Weyl sequence to prevent convergence). I had to 'downsize' though since my Seed is 32 bits instead of 64. Thus, halfword output is used for the random output instead of a word. The seed is using the lower 32 bits of the TB. Ofc, including the upper 32 bits is not a good idea. For more info, visit this link - https://pthree.org/2018/07/30/middle-square-weyl-sequence-prng/ ====== Args: r3 = the amount of cycles the generator will do before spitting the output. All values treated logically. If the user puts 0 as the value, it is auto adjusted to 4. Source: #The following snippet of code is meant to be used as a subroutine reached via a branch-link instruction cmpwi r3, 0 bne+ move_to_ctr li r3, 4 #If user sets r3 arg to 0, adjust it to 4. move_to_ctr: mtctr r3 #LR doesn't need to be backed up for this subroutine mftbl r4 #Seed register li r3, 0 #Square-value register, start at 0 li r5, 0 #Starting Weyl variable, start at 0 clrlwi. r0, r4, 31 #Seed needs to be an odd number bne- loop addi r4, r4, 1 #Make seed odd loop: mullw r3, r3, r3 #Square the Value add r5, r4, r5 #Add the constant seed to Weyl variable. Result is new Weyl variable add r3, r3, r5 #Add Weyl variable to squared value srwi r3, r3, 16 #Place upper 16 bits into lower 16 bits, upper 16 bits are now cleared bdnz+ loop blr #r3 contains random halfword result RE: Random Halfword Generator PPC ASM - JoshuaMK - 11-08-2019 This is really cool. RE: Random Halfword Generator PPC ASM - Vega - 11-08-2019 Thx. It's part of a code I was working on. Thought i would share it. Do you have any ideas for a 64 bit seed? If so, i can use mullw mulhwu for a random word output instead of halfword RE: Random Halfword Generator PPC ASM - JoshuaMK - 11-08-2019 I'll see if I can come up with something |