ASM 8Bit-LFSR

Gast #4401031
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?
Gast #4401045
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?
Gast #4401047
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

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.