

Let’s look at implementing an LFSR at a very low level: assembly language! LFSR Updates in Assembly Such a large assembly implementation wasn’t what I expected here, and perhaps we should try rewriting it. There are a few other quirks, like interaction with chip special function registers taking 2 cycles rather than one, but if you’re just interacting with the 16 W registers and RAM, all the basic instructions take one cycle each.)

(A conditional branch takes one instruction and acts as a NOP if not taken, but if there is a branch, it takes 4 cycles. What we care about is the code for lfsr_step there’s a lot going on there! Excluding the return, we’ve got 27 instructions that take 29 cycles worst-case mov.d is a double-word move that takes two cycles, and all the other instructions take one cycle each, except for branches and jumps if taken. The efficiency of the lfsr_init function doesn’t matter much to us, since it will just be called once.
