Page 1 of 1

Linear feedback shift register in DigiRule assembly

Posted: Fri Aug 30, 2019 3:28 pm
by dylan
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

Re: Linear feedback shift register in DigiRule assembly

Posted: Sat Apr 25, 2020 8:36 pm
by brad
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 :)