I wanna see how fast and small you can make some code to turn a 16 bit register backwards
%1101110 01101010
becomes
%01010110 0111011
I did it in 40 bytes and 156 clocks.
I'll post the code tomorrow.
oh, and whoever wins posts the next challenge.
33 bytes/100 cycles
WIN
Show us. I want to see how you got it to 100 clocks
One sec. Is this accurate? http://www.ticalc.org/pub/text/z80/z80_reference.txt
It's accurate. Your IDE probably has a code counter feature.
What IDE? I'm just counting code. I'm double checking it now.
use wabbitcode for code counting. or use asm8x or something.
wabbitcode is easiest, just highlight it and look at the bottom right corner of the window.
Wait, its 154 clocks. My bad. And the size is 38 bytes. Still win.
hl reversed to hl in 30 bytes and 120 clocks:


Code:
ld a,l ;one byte and 4 clocks
rr h
rla    ;bits 7 and 8; three bytes and 4+8=12 clocks
rr h
rla   ;bits 6 and 9; three bytes and 12 clocks
rr h
rla    ;bits 5 and 10; three bytes and 12 clocks
rr h
rla    ;bits 4 and 11; three bytes and 12 clocks
rr h
rla    ;bits 3 and 12; three bytes and 12 clocks
rr h
rla    ;bits 2 and 13; three bytes and 12 clocks
rr h
rla    ;bits 1 and 14; three bytes and 12 clocks
rr h
rla    ;bits 0 and 15; three bytes and 12 clocks
rr h   ;catch the carry out of the final bit of a=l; 2b, 8c
rlc h  ;rotate it properly
ld l,a ;reassemble; 1b, 4c
KermMartian wrote:
hl reversed to hl in 30 bytes and 120 clocks:


Code:
ld a,l ;one byte and 4 clocks
rr h
rla    ;bits 7 and 8; three bytes and 4+8=12 clocks
rr h
rla   ;bits 6 and 9; three bytes and 12 clocks
rr h
rla    ;bits 5 and 10; three bytes and 12 clocks
rr h
rla    ;bits 4 and 11; three bytes and 12 clocks
rr h
rla    ;bits 3 and 12; three bytes and 12 clocks
rr h
rla    ;bits 2 and 13; three bytes and 12 clocks
rr h
rla    ;bits 1 and 14; three bytes and 12 clocks
rr h
rla    ;bits 0 and 15; three bytes and 12 clocks
rr h   ;catch the carry out of the final bit of a=l; 2b, 8c
rlc h  ;rotate it properly
ld l,a ;reassemble; 1b, 4c
Kerm you stole my routine Sad
38 bytes/154 cycles


Code:
; Reverse bits of 2 bytes
; Input: hl points to first byte
; a and b are destroyed.
; Output: hl points second byte of set.
Reverse16Bit
ld a, (hl)
call reverseA
ld b, a
inc hl
ld a, (hl)
call reverseA
dec hl
ld (hl), a
ld a, b
inc hl
ld (hl), a
ret

reverseA:
ld b,a
rrca
rrca
xor b
and %10101010
xor b
ld b,a
rrca
rrca
rrca
rrca
xor b
and %01100110
xor b
rrca
call Reverse16Bit

Code:
   di
   ld a,h
   ex af, af'
   ld a,l
   rrca
   rrca
   xor l
   and %10101010
   xor l
   ld l,a
   rrca
   rrca
   rrca
   rrca
   xor l
   and %01100110
   xor l
   rrca
   ex af, af'
   rrca
   rrca
   xor h
   and %10101010
   xor h
   ld h,a
   rrca
   rrca
   rrca
   rrca
   xor h
   and %01100110
   xor h
   rrca
   ld l,a
   ex af, af'
   ld h,a
Second place isn't horrible
SirCmpwn, you forgot that reverseA is executed twice. And you miscounted.
Edit: and I got pwnt by the most obvious solution ever. Guess I was trying to be too fancy.
Nicely done, guys. Smile Here's a smaller and slower version of mine (11 bytes and 196 clocks):

Code:
    ld a,l ;one byte and 4 clocks
    ld b,8 ;two bytes and 7 clocks
repeat:
    rr h
    rla    ;three bytes and 4+8=12 clocks
    djnz repeat ;8*7+13 clocks, 2 bytes
    rlc h  ;rotate it properly
    ld l,a ;reassemble; 1b, 4c
Grr, whats the real one? Its quite a bit harder to count by hand.
And KermM - holy crap
28 bytes, 112 cycles

Code:
ld a,l
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rrca
ld l,a


I win Very Happy
Fast and small are most often mutually exclusive.

Pick the more important one next time.
calc84maniac wrote:
28 bytes, 112 cycles

Code:
ld a,l
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rr h
rla
rrca
ld l,a


I win Very Happy


Pwnt

Edit: also its your Turn Calc84 to make a challenge.
Hey, all you did was use my code slightly permuted. Wink Nice job, calc84.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement