Advertisement
Zeda

A_Times_DE-Crazy Z80

Jan 4th, 2012
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. A_Times_DE:
  2. ;Input:
  3. ;     A,DE
  4. ;Outputs:
  5. ;     A is 0
  6. ;     BC is not changed
  7. ;     DE is not changed
  8. ;     HL is the result
  9. ;     z flag is set
  10. ;     c flag is set if the input A is not 0
  11. ;Notes:
  12. ;           If A is 0, 29 cycles
  13. ;Speed: 145+6n+21b cycles
  14. ;           n=floor(log(a)/log(2))
  15. ;           b is the number of bits in the number
  16. ;           Testing over all values of A from 1 to 255:
  17. ;           313.7058824 average cycles
  18. ;           Worst: 355
  19. ;           Best  : 166 (non trivial)
  20. ;Size: 25 bytes
  21.      ld hl,0           ;10
  22.      or a \ ret z     ;9
  23.      cpl \ scf        ;8
  24.      adc a,a         ;4
  25.      jp nc,$+7       ;10         ;45
  26. Loop:
  27.      add a,a          ;4
  28.      jp c,$-1         ;10         ;14(7-n)
  29.  
  30.      add hl,de        ;11         ;11         (the rest are counted below)
  31.      add a,a          ;4           ;4b
  32.      ret z              ;5|11      ;5b+6
  33.      add hl,hl         ;11         ;11b-11
  34.      jp p,$-4         ;21|20     ;20n+b
  35.      jp $-7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement