Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _lshiftc_and_add:
- ; inputs: iy = ptr to src, hl = ptr to dest, a = shift count
- ; ouputs: none
- ; destroys: a, b, c, flags
- ; algorithm:
- ; byte shift: shift by between 1 and 32 (inclusive) bytes by:
- ; shift a to the right 3x (div 8), then and a with 30 to constrain to 30 or less
- ; if a == 0, skip to the bit shift section
- ; set the first a bytes of de to 0
- ; copy 32 - a bytes from hl to de + a
- ; bit shift: shift by between 1 and 7 (inclusive) bits by:
- ; restore original a, then and with 7 to return a value mod 8
- ; return if 0
- ; shift the 32 bytes at hl to the left a times
- push af
- srl a
- srl a
- srl a
- or a
- jr z, .skip_byte_shift
- ; add a to hl
- ld bc, 0
- ld c, a
- add hl, bc
- ; sub 32 - a
- ld b, a
- ld a, 32 ; set c to 32
- sub a, b
- ld b, a
- pop af
- push bc
- and a, 7 ; and a with 7 to get a % 8
- ld b, a
- ld a, 1
- .lshiftc:
- rlca
- djnz .ishiftc
- pop bc ; loop count in b
- ld c, a ; bits multiplier in c
- xor a
- .loop_xor_bytes:
- ld e, (iy)
- ld d, c
- mlt de
- add a, e
- xor (hl)
- ld (hl), a
- ld a, d
- inc iy
- inc hl
- djnz .loop_xor_bytes
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement