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
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