Advertisement
AnthonyCagliano

Untitled

Dec 9th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. _lshiftc_and_add:
  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. srl a
  17. srl a
  18. srl a
  19.  
  20. or a
  21. jr z, .skip_byte_shift
  22.  
  23. ; add a to hl
  24. ld bc, 0
  25. ld c, a
  26. add hl, bc
  27.  
  28. ; sub 32 - a
  29. ld b, a
  30. ld a, 32 ; set c to 32
  31. sub a, b
  32. ld b, a
  33. pop af
  34. push bc
  35. and a, 7 ; and a with 7 to get a % 8
  36. ld b, a
  37. ld a, 1
  38. .lshiftc:
  39. rlca
  40. djnz .ishiftc
  41. pop bc ; loop count in b
  42. ld c, a ; bits multiplier in c
  43. xor a
  44. .loop_xor_bytes:
  45. ld e, (iy)
  46. ld d, c
  47. mlt de
  48. add a, e
  49. xor (hl)
  50. ld (hl), a
  51. ld a, d
  52. inc iy
  53. inc hl
  54. djnz .loop_xor_bytes
  55. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement