Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;+17 bytes -150.5cc
- ;===============================================================
- BC_Div_DE:
- ;===============================================================
- ;Performs BC/DE
- ;Speed: 890+6b+a cycles when DE<256 (1/256 of the time)
- ; 541+6b cycles when DE>=256 (255/256 of the time)
- ; Avg = 566.37890625cc
- ;Size: 52 bytes
- ;Inputs:
- ; BC is the numerator
- ; DE is the denominator
- ;Outputs:
- ; BC is the quotient
- ; HL is the remainder
- ; DE is not changed
- ; A is 0
- ; z flag is set
- ; c flag is reset
- ;===============================================================
- ld hl,0
- ld a,b
- inc d
- dec d
- jr z,upper
- ld l,a
- ld a,c
- ld c,h
- lower:
- ld b,8
- loop:
- rla
- adc hl,hl
- sbc hl,de
- jr nc,$+3
- add hl,de
- djnz loop
- ld b,c
- rla
- cpl
- ld c,a
- ret
- upper:
- ld b,8
- ld a,h
- loop_upper:
- rl c
- rla
- sub e
- jr nc,$+3
- add a,e
- djnz loop_upper
- ld l,a
- ld a,c
- rla
- cpl
- ld c,a
- jp lower
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement