Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Soulthym on July 19, 2013, 09:16:04 am

Title: Looking for a fast 3 bytes left rotation(axe friendly)
Post by: Soulthym on July 19, 2013, 09:16:04 am
Hi! everyone,I was wondering how to make a really fast 3 bytes rotation routine(or not) that is axe friendly, so I came out with this:
Code: [Select]
ld a,(hl)
inc hl
ld b,(hl)
inc hl
ld c,(hl)
ld d,a
rl d
rl c
rl b
rl a
ld (hl),c
dec hl
ld (hl),b
dec hl
ld (hl),a
The hex code is like that
Code: [Select]
7E
23
46
23
4E
57
CB12
CB11
CB10
CB17
71
2B
70
2B
77
Please don't forget it must be axe friendly, so we use it like that:
Code: [Select]
.pointer
Pic1
Asm(7E2346234E57CB12CB11CB10CB17712B702B77)

Sorry if my English is bad, I'm French
Title: Re: Looking for a fast 3 bytes left rotation(axe friendly)
Post by: Runer112 on July 19, 2013, 01:01:15 pm
To rotate 3 bytes pointed to by hl one bit to the left, I think this is the fastest way it can be done:

13 bytes, 79 cycles
Axe: Asm(7E872323CB162BCB162BCE0077)
Source:
Code: [Select]
ld a,(hl)
add a,a
inc hl
inc hl
rl (hl)
dec hl
rl (hl)
dec hl
adc a,0
ld (hl),a

I assume you may want rotation to the right as well:

12 bytes, 80 cycles
Axe: Asm(7E1F23CB1E23CB1E2B2BCB1E)
Source:
Code: [Select]
ld a,(hl)
rra
inc hl
rr (hl)
inc hl
rr (hl)
dec hl
dec hl
rr (hl)


And for what it's worth, your code was already pretty close to mine in terms of speed; 102 cycles for yours versus 79/80 cycles for mine. :)

If you plan on using these code snippets a lot, it may be a good idea to put them in a subroutine and calling it each time you need it, which would save you 10/9 bytes, at the cost of 27 cycles, for each use.
Title: Re: Looking for a fast 3 bytes left rotation(axe friendly)
Post by: Soulthym on July 19, 2013, 06:46:13 pm
I'm so glad you answered me so fast and thank you about that! I have another question: where did you find the timings for "add a,a" I can't find it anywhere! So if you have all the timings in a text file, would it be possible to post it?
Thank you very much!
Title: Re: Looking for a fast 3 bytes left rotation(axe friendly)
Post by: Streetwalrus on July 20, 2013, 03:40:02 am
Here you go. (http://t.eeems.ca/ASMin28Days/ref/z80is.html) The whole z80 instruction set detailed.