Dave VanHorn wrote: > Speed contest: Fast code desired, space is no object. > > Task: Make UP look like Down by rotating all the bits in a byte. > > Input in TEMP, output in TEMP2 or for bonus points, in TEMP, such that > > Input: 7,6,5,4,3,2,1,0 10101110 or AE > > Routine happens, then > > Output: 0,1,2,3,4,5,6,7 01110101 or 75 > > The obvious solution is to clear the output and set the bits with > SBRC like this: > > ; > ;************************************************************************************* > ; > ;Bit swap end for end. > ; > Untwist: > push TEMP2 ; > clr TEMP2 ; > > sbrc TEMP,0 ; > sbr TEMP2,1<<7 ; > > sbrc TEMP,1 ; > sbr TEMP2,1<<6 ; > > sbrc TEMP,2 ; > sbr TEMP2,1<<5 ; > > sbrc TEMP,3 ; > sbr TEMP2,1<<4 ; > > sbrc TEMP,4 ; > sbr TEMP2,1<<3 ; > > sbrc TEMP,5 ; > sbr TEMP2,1<<2 ; > > sbrc TEMP,6 ; > sbr TEMP2,1<<1 ; > > sbrc TEMP,7 ; > sbr TEMP2,1<<0 ; > > mov TEMP,TEMP2 ; > > pop TEMP2 > ret ; > > > > > > Yahoo! Groups Links > > > > > > > > > Solution 1 Cross wire port A to Port B (or any other port combination. Output byte on one port and read back on another. Solution 2 Use a look up table and index the answer by the question byte. 256 bytes + the load register with answer. Don't think you can can quicker than these.
Message
Re: [AVR-Chat] Challenge
2005-06-07 by Richard Austin
Attachments
- No local attachments were found for this message.