Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;+92 bytes, -110cc
- ;===============================================================
- BC_Div_DE:
- ;===============================================================
- ;Performs BC/DE
- ;Speed: 674+6b+a cycles when DE<256 (1/256 of the time)
- ; 431+6b cycles when DE>=256 (255/256 of the time)
- ; Avg = 455.96484375cc
- ;Size: 144 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 b,h
- lower:
- ;-110cc
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
- rla
- cpl
- ld c,a
- ret
- upper:
- ;-106
- ld a,h
- loop_upper:
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
- ld l,a
- ld a,c
- rla
- cpl
- ld b,a
- jp lower
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement