Linear feedback shift register in DigiRule assembly

Post here to discuss all things DigiRule!

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
dylan
newbie
newbie
Posts: 2
Joined: Fri Aug 30, 2019 3:20 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Linear feedback shift register in DigiRule assembly

Post by dylan » Fri Aug 30, 2019 3:28 pm

I wrote a simple blinkenlights of both the addr and data LEDs driven by the RANDA instruction. I wasn't too happy with the number of visible patterns (even though it was pretty), so I decided to implement a simple Galois LFSR. It also suffers from "hey, there seems to be a pattern here" in the blinkenlights, but it was a fun exercise. Anyway, for fun here it is:

Code: Select all

// Some handy constants
%define statusRegister      0xfc
%define addressLEDRegister  0xfe
%define dataLEDRegister     0xff

%define taps                0xf1
%define state               0xf0

// set things up
initsp
speed 32 // slow things down
sbr 2 statusRegister // to show bits
copylr 0xb4 taps
copylr 0x01 state

:Loop
call StepLFSR
copyrr state addressLEDRegister
call StepLFSR
copyrr state dataLEDRegister
jump Loop // Loop forever

// step the LFSR - state updated
:StepLFSR
bcrss 0 state  // is the bottom bit set?
jump NoXor   // if so, skip the xor

// otherwise shift & xor taps
shiftrr state
copyra state
xorra taps
copyar state
return

:NoXor
shiftrr state
return
For reference, here's the Cryptol code I used as the source for this:

Code: Select all

init  = 0b1010110011100001
fibtaps = 0xb400 // from wikipedia - produces a maximal cycle

galoisLFSR : {n} (fin n) => [n] -> [n] -> [inf][n]
galoisLFSR seed taps = elts where
    elts = [seed] # [ nextState state | state <- elts ]
    nextState : [n] -> [n]
    nextState s = if s!0 then n ^ taps else n where n = s >> 1

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Linear feedback shift register in DigiRule assembly

Post by brad » Sat Apr 25, 2020 8:36 pm

I'm sorry for the late reply here dylan, but I don't often drop by my own forum...

Great work with your code and I appreciate you sharing it, i'll have to punch it into my Digirule 2A and give it a go :)

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 1 guest