Advertisement
AnthonyCagliano

Untitled

Dec 9th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. _lshiftc:
  2. ; inputs: iy = ptr to src, hl = ptr to dest, a = shift count
  3. ; ouputs: none
  4. ; destroys: a, b, c, flags
  5. ; algorithm:
  6. ; byte shift: shift by between 1 and 32 (inclusive) bytes by:
  7. ; shift a to the right 3x (div 8), then and a with 30 to constrain to 30 or less
  8. ; if a == 0, skip to the bit shift section
  9. ; set the first a bytes of de to 0
  10. ; copy 32 - a bytes from hl to de + a
  11. ; bit shift: shift by between 1 and 7 (inclusive) bits by:
  12. ; restore original a, then and with 7 to return a value mod 8
  13. ; return if 0
  14. ; shift the 32 bytes at hl to the left a times
  15. push af
  16. push hl
  17. push iy
  18.  
  19. srl a
  20. srl a
  21. srl a
  22.  
  23. or a
  24. jr z, .skip_byte_shift
  25.  
  26. ; add a to hl
  27. ld bc, 0
  28. ld c, a
  29. add hl, bc
  30.  
  31. ; sub 32 - a
  32. ld b, a
  33. ld a, 32 ; set c to 32
  34. sub a, b
  35.  
  36. ld b, a
  37. .loop_xor_bytes:
  38. ld a, (iy)
  39. xor (hl)
  40. ld (hl), a
  41. inc iy
  42. inc hl
  43. djnz .loop_xor_bytes
  44.  
  45. .skip_byte_shift:
  46. pop iy
  47. pop hl ; dest into hl now
  48. pop af ; return original a
  49. and a, 7 ; and a with 7 to get a % 8
  50. ret z
  51. ld b, a
  52. ld a, 1
  53. .ishiftc:
  54. rlca
  55. djnz .ishiftc
  56. ld c, a
  57. ld b, 32
  58. xor a
  59. .shift_bits:
  60. ld e, (iy)
  61. ld d, c
  62. mlt de
  63. add a, e
  64. xor (hl)
  65. ld (hl), a
  66. ld a, d
  67. inc hl
  68. djnz .shift_bits
  69. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement