This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

inverter byte

elegante inversion.


/*------------------------------------------------------------------------------

                                        INVERSION DE BYTE 8 BIT, LSB ->  MSB

------------------------------------------------------------------------------*/
unsigned char mr;

unsigned char invertir_byte (mr) {

  mr = (mr & 0x0F) << 4 | (mr & 0xF0) >> 4;
  mr = (mr & 0x33) << 2 | (mr & 0xCC) >> 2;
  mr = (mr & 0x55) << 1 | (mr & 0xAA) >> 1;

return (mr);

}


Parents
  • ;=(FUNCTION)=================================================================
    ;
    ; Name       : SwapByte
    ;
    ; Action     : Swap bit order within byte
    ;
    ; Parameters : UByte Src (R7)
    ;
    ; Result     : UByte (R7)
    ;
    ; Notes      : Src - Data byte to undergo 'swapping'
    ;
    ;=(END)======================================================================
    
    ?PR?_SwapByte?SwapByte Segment Code
    
      Rseg ?PR?_SwapByte?SwapByte
    
    _SwapByte:
    
      MOV   A,R7        ;Transfer to 'bit addressable' register
      MOV   C,ACC.0     ;Take bits (low to high)
      MOV   B.7,C       ;Transfer to another 'bit addressible' register
      MOV   C,ACC.1     ;And store (high to low)
      MOV   B.6,C
      MOV   C,ACC.2
      MOV   B.5,C
      MOV   C,ACC.3
      MOV   B.4,C
      MOV   C,ACC.4
      MOV   B.3,C
      MOV   C,ACC.5
      MOV   B.2,C
      MOV   C,ACC.6
      MOV   B.1,C
      MOV   C,ACC.7
      MOV   B.0,C
      MOV   R7,B        ;Job done
      RET
    

Reply
  • ;=(FUNCTION)=================================================================
    ;
    ; Name       : SwapByte
    ;
    ; Action     : Swap bit order within byte
    ;
    ; Parameters : UByte Src (R7)
    ;
    ; Result     : UByte (R7)
    ;
    ; Notes      : Src - Data byte to undergo 'swapping'
    ;
    ;=(END)======================================================================
    
    ?PR?_SwapByte?SwapByte Segment Code
    
      Rseg ?PR?_SwapByte?SwapByte
    
    _SwapByte:
    
      MOV   A,R7        ;Transfer to 'bit addressable' register
      MOV   C,ACC.0     ;Take bits (low to high)
      MOV   B.7,C       ;Transfer to another 'bit addressible' register
      MOV   C,ACC.1     ;And store (high to low)
      MOV   B.6,C
      MOV   C,ACC.2
      MOV   B.5,C
      MOV   C,ACC.3
      MOV   B.4,C
      MOV   C,ACC.4
      MOV   B.3,C
      MOV   C,ACC.5
      MOV   B.2,C
      MOV   C,ACC.6
      MOV   B.1,C
      MOV   C,ACC.7
      MOV   B.0,C
      MOV   R7,B        ;Job done
      RET
    

Children