Advertisement
Zeda

BC_Div_DE

Mar 5th, 2014
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BC_Div_DE:
  2. ;756 t-states worst case for old version
  3. ;227 bytes
  4.     ld a,b \ or a \ jp z,C_Div_DE
  5. ;If D>0, then the first iteration will yield carry=B, acc=0
  6.     ld hl,0
  7.     inc d \ dec d
  8.     jr z,BC_Div_E
  9.     ld l,b \ ld b,h
  10.     ld a,c
  11.     jp sub0
  12. BC_Div_E:
  13.     xor a
  14.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  15.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  16.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  17.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  18.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  19.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  20.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  21.     rl b \ rla \ sub e \ jr nc,$+3 \ add a,e
  22.     ld d,a
  23.     ld a,b \ rla \ cpl \ ld b,a
  24.     ld a,d
  25.     bit 7,e \ jr z,C_Div_E
  26.     ld l,a
  27.     ld d,h
  28.     ld a,c
  29. sub0:
  30.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  31.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  32.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  33.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  34.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  35.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  36.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  37.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  38.     rla \ cpl \ ld c,a
  39.     ret
  40.    
  41. C_Div_DE:
  42.     ld a,c \ or a \ ret z
  43.     inc d \ dec d \ jr z,$+4 \ ld c,b \ ret
  44.     xor a
  45. C_Div_E:
  46.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  47.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  48.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  49.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  50.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  51.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  52.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  53.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  54.     ld a,c \ rla \ cpl \ ld c,a
  55.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement