If I'm not mistaken you could use a 16 byte lookup for the nybbles and then use the efficency of the swap instruction, quicker I believe than rotating all 8 bits and less code space than the full lookup table. Doug ----- Original Message ----- From: Adam Bryant To: Sent: Friday, October 29, 1999 3:54 PM Subject: Re: Efficient way to reverse a byte? > Jim, > Your choices are likely to be fast execution and big code usage OR slow > execution and small code usage. > > As Wagner suggested, fastest would be a 256 byte lookup table (but it > uses up 256 bytes for the lookup table). > > A small, slower approach is to rotate the source byte right one bit > (putting the rightmost bit in the carry flag), then rotate the > destination byte left one bit (putting the carry flag in the rightmost > bit of your destination register). Repeat this cycle 8 times. Your > destination byte will have to be a temp register, then when done move the > temp register back to the original source register. I would estimate > this could be done in 10 to 15 bytes of code and 50 to 70 instruction > cycles. > > Obviously I am thinking like the C programmer I am and someone like > Dimitry could probably give you a method for accomplishing the same thing > in 5 bytes of code and 10 cycles. :-) > > Hope this helps, > Adam > > On Fri, 29 Oct 1999 14:48:54 +0100 Jim Main writes: > > I'm sure I saw an easy way to reverse a byte some time ago in this > > list, but > > I've forgotten it.. > > > > I want to change b7 b6 b5 b4 b3 b2 b1 b0 to b0 b1 b2 b3 b4 b5 > > b6 b7. > > > > Quickest & most code efficient?? > > > > Jim > > --- > > Adam Bryant (age 0x23) > abryant@peaktech.com (work) > adamdb@juno.com (home) > Parker, CO, USA > Robotics, RC Airplanes, anything using a PIC > > ___________________________________________________________________ > Get the Internet just the way you want it. > Free software, free e-mail, and free Internet access for a month! > Try Juno Web: http://dl.www.juno.com/dynoget/tagj.