Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/01/05 15:56
Read: times


 
#90817 - Byte Bit Reversal
Responding to: ???'s previous message
Here are two methods, the latter is the most compact that I have come across.
//
//  Fast Char Bit Reverse
//
//  Author:     Graham Cole
//
//  Input:      c       -   8-bit word R7.
//
//  Output:     R7 is c with the bit values reversed.
//
//  Function:   
//
//  Notes:      Two methods are presented, the shorter of which
//              is based on an idea by Peter Dannegger.
//

#pragma ASM

$REGUSE _fast_char_bit_reverse( A, PSW, R7 )

#pragma ENDASM


unsigned char fast_char_bit_reverse( char c )
{
    #pragma ASM
                                    ;
fast_char_bit_reverse:              ;
                                    ;
    #if 0
                                    ;
        MOV     A,R7                ;C 76543210
                                    ;  hgfedcba
        ANL     A,#0x55             ;  -g-e-c-a
        RL      A                   ;  g-e-c-a-
        XCH     A,R7                ;  hgfedcba
        ANL     A,#0xAA             ;  h-f-d-b-
        RR      A                   ;  -h-f-d-b
        ORL     A,R7                ;  ghefcdab
        MOV     R7,A                ;
                                    ;
        ANL     A,#0x33             ;  --ef--ab
        RL      A                   ;  -ef--ab-
        RL      A                   ;  ef--ab--
        XCH     A,R7                ;  ghefcdab
        ANL     A,#0xCC             ;  gh--cd--
        RR      A                   ;  -gh--cd-
        RR      A                   ;  --gh--cd
        ORL     A,R7                ;  efghabcd
                                    ;
        SWAP    A                   ;  abcdefgh
                                    ;
        MOV     R7,A                ;
                                    ;
    #else
                                    ;
        MOV     A,R7                ;C 76543210
                                    ;
        MOV     C,Acc.1             ;b hgfedcba
        RLC     A                   ;h gfedcbab
        MOV     Acc.2,C             ;h gfedchab
        MOV     C,Acc.3             ;c gfedchab
        RLC     A                   ;g fedchabc
        MOV     Acc.4,C             ;g fedghabc
        MOV     C,Acc.5             ;d fedghabc
        RLC     A                   ;f edghabcd
        MOV     Acc.6,C             ;f efghabcd
        SWAP    A                   ;f abcdefgh
                                    ;
        MOV     R7,A                ;
                                    ;
    #endif

    #pragma ENDASM

    return( c );
}


List of 36 messages in thread
TopicAuthorDate
Reversing Algorithm            01/01/70 00:00      
   remembered this one            01/01/70 00:00      
      the fastest code in the west            01/01/70 00:00      
         Am I wrong            01/01/70 00:00      
            not as simple, but less table            01/01/70 00:00      
               lookup table            01/01/70 00:00      
                  nope            01/01/70 00:00      
                     swap, the nibble mirror            01/01/70 00:00      
                        nibble-wise?            01/01/70 00:00      
                     nope nope            01/01/70 00:00      
                        noipe, nope, nope            01/01/70 00:00      
                            noipe, nope, nope, nope            01/01/70 00:00      
                              Ok, Ok. Ok, OK            01/01/70 00:00      
                                 max.255 entries - or the tricks :-)            01/01/70 00:00      
                                    the value of verification            01/01/70 00:00      
                  Mirrored tracks            01/01/70 00:00      
                     Why ?            01/01/70 00:00      
                        Working fine            01/01/70 00:00      
                           why you post wrong code ?            01/01/70 00:00      
                              Yes. Code has bug - Peter            01/01/70 00:00      
                                 efficiency            01/01/70 00:00      
                                    Obvious Vs Smart code            01/01/70 00:00      
                                       sorry            01/01/70 00:00      
                                          No offence - only learning            01/01/70 00:00      
   One byte-reversing solution            01/01/70 00:00      
   Byte Bit Reversal            01/01/70 00:00      
      Re: Byte Bit Reversal            01/01/70 00:00      
   Bit Addressing solution!            01/01/70 00:00      
      Hardware?            01/01/70 00:00      
      2 byte of ram or 2 port?            01/01/70 00:00      
   Three ways:            01/01/70 00:00      
      Three (smart) ways            01/01/70 00:00      
      Thanks, Peter, but...            01/01/70 00:00      
         its faster            01/01/70 00:00      
   Topic has been discussed before            01/01/70 00:00      
   You could try a CPLD            01/01/70 00:00      

Back to Subject List