Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;===============================================================
- HL_Div_BC_Signed:
- ;===============================================================
- ;Performs HL/BC
- ;Speed: 1344-55n-2b
- ; b is the number of set bits in the result
- ; n is the number of leading zeroes in the absolute value of HL, minus 1
- ; add 24 if HL is negative
- ; add 24 if BC is negative
- ; add 28 if the result is negative
- ;Size: 68 bytes
- ;Inputs:
- ; HL is the numerator
- ; BC is the denominator
- ;Outputs:
- ; DE is the quotient
- ; HL is the remainder
- ; BC is not changed
- ;Destroys:
- ; A
- ;===============================================================
- ld a,h
- xor b
- push af
- ;absHL
- xor b
- jp p,$+9
- xor a \ sub l \ ld l,a
- sbc a,a \ sub h \ ld h,a
- ;absBC:
- xor b
- jp p,$+9
- xor a \ sub c \ ld c,a
- sbc a,a \ sub b \ ld b,a
- ld de,0
- adc hl,hl
- jr z,EndSDiv
- ld a,16
- add hl,hl
- dec a
- jp nc,$-2
- ex de,hl
- jp jumpin
- Loop1:
- add hl,bc ;--
- Loop2:
- dec a ;4
- jr z,EndSDiv ;12|23
- sla e ;--
- rl d ;--
- jumpin: ;
- adc hl,hl ;15
- sbc hl,bc ;15
- jr c,Loop1 ;23-2b ;b is the number of bits in the absolute value of the result.
- inc e ;--
- jp Loop2 ;--
- EndSDiv:
- pop af \ ret p
- xor a \ sub e \ ld e,a
- sbc a,a \ sub d \ ld d,a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement