-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathlfsr.mu4
42 lines (33 loc) · 1.33 KB
/
lfsr.mu4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
loading MSP430 Linear-feedback shift registers
__meta
( 32-bit Galois-type shift register. Taps at bits 32, 30, 26, 25.)
code lfsr-galois ( lo hi #bits - lo' hi')
y pop x pop
begin
clrc y ror x ror ( lsb now in carry)
CS if %1010_0011_0000_0000 # y xor then
1 # top sub 0= until
x push y top mov next ;c
| This takes about 50 minutes to run, so don't get impatient! After 50
| minutes or so, run "rechat" to re-connect to the target and fetch its
| stack. The value on the stack should be the double number ffff ffff - the
| number of states in a 32-bit LFSR.
code lfsr-galois-len ( - lo hi)
w clr ( counter lo) top push top clr ( counter hi)
1 # x mov ( lfsr lo) 0 # y mov ( lfsr hi)
begin begin
1 # w add 0 # top addc ( incr count)
clrc y ror x ror ( lsb now in carry)
CS if %1010_0011_0000_0000 # y xor then
1 # x cmp 0= until
0 # y cmp 0= until
w push next ;c
| If you load the FR6989 LCD code you can get an indication that the
| computation has finished. The display will show 0 while it is running and
| 1 when it finishes.
.target. .contains lcd-init .if
: mondo lcd-init 0 digit>seg 0 lcd! lfsr-galois-len 1 digit>seg 0 lcd! ;
.then