From ccslist@ewol.com Thu Mar 27 13:27:36 1997
Date: Sat, 15 Mar 1997 14:57:19 -0500
From: Customized Controller Solutions <ccslist@ewol.com>
To: 8051code@emily.keilsoftware.com
Subject: Seeking ASM code for extract 5 bits from 16 bit word.

Seeking ASM code for extract 5 bits from 16 bit word.

##### Begin Example: ###################################################

The 16 bit word:

_HiByte   _LoByte
0101 0111 0101 0101  <--- work on this 16 bit word

0000 0111 1100 0000  <--- get these into the 5 lsb's of a resultant word.
      ^^^ ^^
      ||| ||
Extract These BITS.

Result = 11101 == 1Dh == 29d
##### End Example: #####################################################

This piece of code will rotate the bits of _WORKBYTE to the right 
by the number in __MYBITS and place the value in the least significant 
4 bits.  The result is then placed in __PRODUCT

Any criticism is welcome and appreiated.  I want to become a better 
programmer.

#ASM
;
    MOV     DPTR,#__MYBITS       ; Move Data Pointer to RAM
                                         ; X-reg with # of bits to shift
    MOVX    A, @DPTR                 ; Put val at DPTR into ACC
    MOV _CCSTemp1,A              ; Store the value in _CCSTemp1
    JNZ StartShift1              ; If __MYBITS <> 0 THEN Continue
    SJMP    ExitShift1               ; Else Exit Code
;
StartShift1:
    MOV A,_WORKBYTE              ; Word to work on.
ShiftLp1:
    RR  A
    DJNZ    _CCSTemp1,ShiftLp1       ; IF more shifts left then repeat
;
ExitShift1:
    MOV _WORKBYTE,A              ; Put the shifted bits in ACC
    ANL A,#00001111B             ;
    MOV     DPTR,#__PRODUCT      ; Move Data Pointer to RAM
    MOVX    @DPTR,A              ; Put the __Product into RAM BYTE
;
#ASM_END


The 8051 Code mailing list is maintained by Keil Software.
Check http://www.keil.com/ for more information.
