lfsr.asm

来自「胎压检测发送端汇编源码-tpms-transmitters」· 汇编 代码 · 共 52 行

ASM
52
字号
* LFSR.asm

* This file contains the soft implementation of the linear feedback shift register.

                                                ;First, break the seed into eight
                                                ; registers, 1 bit each.

LFSR:           LDX     #$08                            ;Bit counter
GetSeedBit:     ROL     SEED                            ;Bump a data bit into carry
                ROR     D_REG-1,X                       ;Snatch the carry bit in a register
                DBNZX   GetSeedBit                      ;Get the next bit

                                                ;Next, perform the flip-flop action
                                                ; with the exclusive OR where needed.
                LDX     #Q_REG
                MOV     D_REG+7,X+                      ;Q1 = D8
                MOV     D_REG,X+                        ;Q2 = D1
                LDA     D_REG+1
                EOR     D_REG+7
                STA     ,X                              ;Q3 = D2 ^ D8
                INCX
                MOV     D_REG+2,X+                      ;Q4 = D3
                LDA     D_REG+3
                EOR     D_REG+7
                STA     ,X                              ;Q5 = D4 ^ D8
                INCX
                LDA     D_REG+4
                EOR     D_REG+7
                STA     ,X                              ;Q6 = D5 ^ D8
                INCX
                LDA     D_REG+5
                EOR     D_REG+7
                STA     ,X                              ;Q7 = D6 ^ D8
                INCX
                LDA     D_REG+6
                EOR     D_REG+7
                STA     ,X                              ;Q8 = D7 ^ D8

                                                ;Finally, move the new data into the
                                                ; SEED register.

PlaceSeedBit:   LDX     #$08                            ;Bit counter
                ROL     Q_REG-1,X                       ;Bump the data bit into carry
                ROL     SEED                            ;Rotate the data bits into the Seed
                DBNZX   PlaceSeedBit                    ;Place the next bit

                LDX     #$16
Clr_NextReg:    CLR     D_REG-1,X
                DBNZX   Clr_NextReg

                RTS

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?