Forum: Mikrocontroller und Digitale Elektronik ASM 8Bit-LFSR


von SeDa (Gast)


Lesenswert?

Hallo,

hier ein ASM Code für ein 8Bit-LFSR mit dem Primitiven Polynom 8, 6, 5, 
4 den ich gerade schnell geschrieben habe.
1
LFSR:
2
  MOV temp, rand    ;alten Wert laden
3
  SWAP temp  ;temp Bit 3 zu Bit 7
4
  ANDI temp, 0b1000000  ;temp Bit 7 freistellen
5
  EOR rand, temp  ;EOR rand Bit 7 und "Bit 3"
6
  MOV temp, rand  ;alten Wert laden
7
  LSL temp  ;temp Bit 6 in Carry, Bit 5 zu Bit 7
8
  LSL temp
9
  LSL temp
10
  ANDI temp, 0b1000000  ;temp Bit 7 freistellen
11
  EOR rand, temp  ;EOR rand Bit 7 und "Bit 5"
12
  ROR temp      ;Carry zu temp Bit 7
13
  ANDI temp, 0b1000000  ;temp Bit 7 freistellen
14
  EOR temp, rand  ;EOR rand Bit 7 und "Bit 6"
15
  LSL temp  ;temp Bit 7 in Carry
16
  ROL rand  ;Carry in rand Bit 0
17
18
  RET

Fällt jemandem noch eine kürzere Methode ein?

von SeDa (Gast)


Lesenswert?

So, da ist mir selber eine ein Takt kürzere Methode eingefallen:
1
LFSR3:
2
  MOV temp, rand  ;alten Wert laden
3
  SWAP temp  ;temp Bit 3 zu Bit 7
4
  ANDI temp, 0b1000000  ;temp Bit 7 freistellen
5
  EOR rand, temp  ;EOR rand Bit 7 und "Bit 3"
6
  MOV temp, rand  ;alten Wert laden
7
  LSR temp  ;temp Bit 4 zu 3 und Bit 5 zu 4
8
  SWAP temp  ;temp Bit 3 zu 7 und Bit 4 zu 0
9
  LSL temp  ;temp Bit 7 in Carry und Bit 0 wiederherstellen
10
  LSR temp
11
  ADC temp, null  ;Quasi EOR temp Bit 0 und Carry
12
  LSL rand  ;rand Bit 7 (enthält bereits EOR aus Bit 7 und 3) in Carry
13
  ADC temp, null  ;Quasi EOR temp Bit 0 (enthält EOR aus rand Bit 5 und 6) und Carry (enthält EOR aus rand Bit 7 und 3)
14
  ANDI temp, 0b0000001  ;temp Bit 0 (enthält EOR aus allen) freistellen
15
  OR rand, temp  ;temp Bit 0 an rand anhängen
16
17
  RET

Findet jemand Fehler oder eine bessere Methode?

von Dr.PillePalle (Gast)


Lesenswert?

;**********************************
Init_Random:        ;first time
  ldi  TEMP,$AA  ;Init the random number generator
  mov  RAND1,TEMP  ;since a 00,00,00 state will not
  mov  RAND2,TEMP  ;progress.
  mov  RAND3,TEMP  ;you can get a timer to pre load first time
  ret
1
;**********************************************************
2
; simple 24bit random generator
3
;**********************************************************
4
random:
5
  push temp
6
  rol  RAND1    ;Shift the bits ->Carry
7
  rol  RAND2    ;RAND are register or Ram
8
  rol  RAND3
9
  BRCC rr2
10
  ldi TEMP,0x87
11
  eor RAND1,TEMP
12
rr2:
13
  pop temp
14
  ret

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.