The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine   
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

Reversing bits within data byte AN709 Author: Greg Goodhue,


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet




Reversing bits within data byte
AN709
Author: Greg Goodhue, Microcontroller Product Planning, Philips Semiconductors, Sunnyvale,
Implementing algorithm reverse bits within data byte notorious producing inefficient code most processors. This function serve case study trade code size performance shows some methods that might employed similar types data conversion situations. Here four solutions shown implement byte reverse function. first version (Listing uses very simple approach. result produced shifting initial data value shifting same back into result value. This repeated loop each bit. Since shift operations done opposite directions, result value reversal initial value. This version smallest size, using only bytes. However, takes clock periods complete. Listing uses same method first, "unfolds" loop eliminate counting branching overhead. What left instructions from inside loop repeated eight times. Unfolding loop gives faster execution, clocks this case. code size grows somewhat bytes. third method (Listing uses partial lookup table reverse nibble time assemble complete byte from lookup values. reversed byte, upper nibble result consists reversed bits lower nibble initial value, while lower nibble result consists reversed bits upper nibble initial value. code example uses each nibble initial value index into lookup table, which provides nibble result data. partial results then combined produce complete result. This version uses bytes both code lookup table, requires only clock periods complete. final method shown (Listing uses full lookup table produce entire result very quickly. initial data byte used index into lookup table value from table complete result byte. This method produces result only clocks. However, code plus lookup table occupies fairly large amount code space: bytes.
CONCLUSION
These examples show code size often traded execution speed, execution speed code size, depending application's requirements. This summarized Figure Other solutions this particular algorithm certainly possible other algorithms will likely have different types solutions with different resulting tradeoffs.
CODE BYTES CLOCKS
LISTING LISTING LISTING LISTING
SU00819
Figure Tradeoff code size performance.
1996
Reversing bits within data byte
AN709
LISTING
Listing Smallest solution terms code space: Enter with value reversed R0L, result R0H. This works shifting register direction back other. count,#8 clks loop: r0l,#1 clks r0h,#1 clks djnz count,loop clks total time 8*(4+4) clocks
LISTING
Listing Solution with loop "unfolded". Enter with value reversed R0L, result R0H. This works shifting register direction back other. r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks r0l,#1 clks r0h,#1 clks total time 8*(4+4) clocks
1996
Reversing bits within data byte
AN709
LISTING
Listing Fastest solution (without using byte lookup table): Enter with value reverse R4L, result returned R0L. This works reversing each nibble using look table reversing nibbles separately part procedure. r6,#LUT1 clks push clks r4l,#$0f clks movc a,[a+dptr] clks r0l,r4l clks r0l,#4 clks clks r4l,#$f0 clks r4l,#4 clks movc a,[a+dptr] clks r0l,r4l clks this nibble reverse lookup table: LUT1: total time clocks
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111
LISTING
Listing Fastest solution (using byte lookup table): Enter with value reverse R4L, result returned R0L. r6,#LUT2 clks movc a,[a+dptr] clks r0l,r4l clks this byte reverse lookup table: LUT2: 00000000 00000000 00000001 10000000 00000010 01000000 00000011 11000000 total clocks
1996

Other recent searches


XN04502G - XN04502G   XN04502G Datasheet
SD1650 - SD1650   SD1650 Datasheet
MPC5604B - MPC5604B   MPC5604B Datasheet
SPC560B - SPC560B   SPC560B Datasheet
MABAES0015 - MABAES0015   MABAES0015 Datasheet
JJJ245 - JJJ245   JJJ245 Datasheet
ACF321825 - ACF321825   ACF321825 Datasheet
74ACTQ02 - 74ACTQ02   74ACTQ02 Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive