Advertisement
foreverfugazi

hamming

Sep 12th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. .data
  2. num: .byte 0xa2
  3.  
  4. .text
  5. la x1, num # loads address
  6. lb x2, 0(x1) # loads data
  7.  
  8. # block below performs xor(1, 3, 5, 7, 9, 11)
  9. mv x3, x2
  10. srli x4, x3, 1
  11. srli x5, x3, 3
  12. srli x6, x3, 4
  13. srli x7, x3, 6
  14. xor x3, x3, x4
  15. xor x3, x3, x5
  16. xor x3, x3, x6
  17. xor x3, x3, x7
  18. andi x10, x3, 1
  19.  
  20. # block below performs xor(2, 3, 6, 7, 10, 11)
  21. mv x3, x2
  22. srli x4, x3, 2
  23. srli x5, x3, 3
  24. srli x6, x3, 5
  25. srli x7, x3, 6
  26. xor x3, x3, x4
  27. xor x3, x3, x5
  28. xor x3, x3, x6
  29. xor x3, x3, x7
  30. andi x3, x3, 1
  31. slli x3, x3, 1
  32. or x10, x10, x3 # c1|c0
  33.  
  34. # block below performs xor(4, 5, 6, 7, 12)
  35. mv x3, x2
  36. srli x4, x3, 1
  37. srli x5, x3, 2
  38. srli x6, x3, 3
  39. srli x7, x3, 7
  40. xor x3, x5, x4
  41. xor x3, x3, x6
  42. xor x3, x3, x7
  43. andi x3, x3, 1
  44. slli x3, x3, 3
  45. or x10, x10, x3 # c2_c1|c0
  46.  
  47. # block below performs xor(8, 9, 10, 11, 12)
  48. mv x3, x2
  49. srli x4, x3, 4
  50. srli x5, x3, 5
  51. srli x6, x3, 6
  52. srli x7, x3, 7
  53. xor x3, x5, x4
  54. xor x3, x3, x6
  55. xor x3, x3, x7
  56. andi x3, x3, 1
  57. slli x3, x3, 7
  58. or x10, x10, x3 # c3___c2_|c1|c0
  59.  
  60. # block below inserts data bits in respective postitions
  61. andi x4, x2, 1
  62. slli x4, x4, 2
  63. or x10, x10, x4 # c3___c2|d0|c1|c0
  64. andi x4, x2, 0x0e
  65. slli x4, x4, 3
  66. or x10, x10, x4 # c3|d3|d2|d1|c2|d0|c1|c0
  67. andi x4, x2, 0xf0
  68. slli x4, x4, 4
  69. or x10, x10, x4 # d7|d6|d5|d4|c3|d3|d2|d1|c2|d0|c1|c0
  70. sw x10, 4(x1) #stores result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement