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