Advertisement
Zeda

BC_Times_DE (fast, avg=~594.6874)

Apr 16th, 2016
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mul16:
  2. ;Inputs:
  3. ;   BC,DE are unsigned integers
  4. ;Output:
  5. ;   HL:DE is the 32-bit product
  6. ;Destroys:
  7. ;   A,B,C
  8. ;min: 359cc
  9. ;max: 717cc
  10. ;avg: 596.34375cc
  11. ;92 bytes
  12.     ld a,c
  13.     call DE_Times_A
  14.     push hl
  15.     push af
  16.     ld a,b
  17.     call DE_Times_A+2
  18.     pop bc
  19.     pop de
  20. ;AHL
  21. ; BDE
  22.     ld c,d
  23.     add hl,bc
  24.     adc a,0
  25. ;AHLE
  26.     ld d,l
  27.     ld l,h
  28.     ld h,a
  29. ;HLDE
  30.     ret
  31. DE_Times_A:
  32. ;Input: DE,A
  33. ;Output: A:HL is the product, C=0, B,DE unaffected, z flag set if result is zero, c flag set if A is input as 1, else nc.
  34. ;A:128~255 219+6{0,10}+{0,19}    avg=258.5   *1/2
  35. ;A:64~127  203+5{0,10}+{0,19}    avg=237.5   *1/4
  36. ;A:32~63   187+4{0,10}+{0,19}    avg=216.5   *1/8
  37. ;A:16~31   171+3{0,10}+{0,19}    avg=195.5   *1/16
  38. ;A:8~15    155+2{0,10}+{0,19}    avg=174.5   *1/32
  39. ;A:4~7     139+{0,10}+{0,19}     avg=153.5   *1/64
  40. ;A:2~3     123+{0,19}            avg=132.5   *1/128
  41. ;A:1       107cc                 avg=107     *1/256
  42. ;A:0       119cc                 avg=119     *1/256
  43. ;overall avg: 237.671875cc
  44.     ld c,0
  45.     ld h,d
  46.     ld l,e
  47.     rla \ jr c,mul_07
  48.     rla \ jr c,mul_06
  49.     rla \ jr c,mul_05
  50.     rla \ jr c,mul_04
  51.     rla \ jr c,mul_03
  52.     rla \ jr c,mul_02
  53.     rla \ jr c,mul_01
  54.     rla
  55.     ret c
  56.     ld h,a
  57.     ld l,a
  58.     ret
  59. mul_07:
  60.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  61. mul_06:
  62.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  63. mul_05:
  64.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  65. mul_04:
  66.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  67. mul_03:
  68.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  69. mul_02:
  70.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,c
  71. mul_01:
  72.     add hl,hl \ rla \ ret nc \ add hl,de \ adc a,c
  73.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement