PN_generator.s 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # mach: bfin
  2. // GENERIC PN SEQUENCE GENERATOR
  3. // Linear Feedback Shift Register
  4. // -------------------------------
  5. // This solution implements an LFSR by applying an XOR reduction
  6. // function to the 40 bit accumulator, XORing the contents of the
  7. // CC bit, shifting by one the accumulator, and inserting the
  8. // resulting bit on the open bit slot.
  9. // CC --> ----- XOR--------------------------
  10. // | | | | | |
  11. // | | | | | |
  12. // +------------------------------+ v
  13. // | b0 b1 b2 b3 b38 b39 | in <-- by one
  14. // +------------------------------+
  15. // after:
  16. // +------------------------------+
  17. // | b1 b2 b3 b38 b39 in |
  18. // +------------------------------+
  19. // The program shown here is a PN sequence generator, and hence
  20. // does not take any input other than the initial state. However,
  21. // in order to accept an input, one simply needs to rotate the
  22. // input sequence via CC prior to applying the XOR reduction.
  23. .include "testutils.inc"
  24. start
  25. loadsym P1, output;
  26. init_r_regs 0;
  27. ASTAT = R0;
  28. // load Polynomial into A1
  29. A1 = A0 = 0;
  30. R0.L = 0x1cd4;
  31. R0.H = 0xab18;
  32. A1.w = R0;
  33. R0.L = 0x008d;
  34. A1.x = R0.L;
  35. // load InitState into A0
  36. R0.L = 0x0001;
  37. R0.H = 0x0000;
  38. A0.w = R0;
  39. R0.L = 0x0000;
  40. A0.x = R0.L;
  41. P4 = 4;
  42. LSETUP ( l$0 , l$0end ) LC0 = P4;
  43. l$0: // **** START l-LOOP *****
  44. P4 = 32;
  45. LSETUP ( m$1 , m$1 ) LC1 = P4; // **** START m-LOOP *****
  46. m$1:
  47. A0 = BXORSHIFT( A0 , A1, CC );
  48. // store 16 bits of outdata RL1
  49. R1 = A0.w;
  50. l$0end:
  51. [ P1 ++ ] = R1;
  52. // Check results
  53. loadsym I2, output;
  54. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x5adf );
  55. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x2fc9 );
  56. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0xbd91 );
  57. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x5520 );
  58. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x80d5 );
  59. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x7fef );
  60. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x34d1 );
  61. R0.L = W [ I2 ++ ]; DBGA ( R0.L , 0x915c );
  62. pass
  63. .data;
  64. output:
  65. .dw 0x0000
  66. .dw 0x0000
  67. .dw 0x0000
  68. .dw 0x0000