Shift arithmetic left?

Status
Not open for further replies.

Manuv16589

New Member
Hi members,
arithmetic shift left in any processor is shifting out msb and adding 0s to lsb. Can it be the same for signed numbers? If so we lose the sign of number?
For ex:if 10001011 is signed number and is arithmetic shifted left by 1 count then the result is 00010110. Havent we lost the sign of number?
 
Last edited:

hi,
b7, the Sign bit is left shifted into CARRY, so you could Test the Cy bit.
 
There are three kinds of shifts, arithmetical, logical, and cyclical.
Logical shift left does what you described, it doesn't preserve the sign bit.
Arithmetical shift keeps the sign bit when shifting left and extends the bit when shifting right.
 
Last edited:
ASL can be achieved by doing,
Code:
       rlf    file,f       ;move b7 into carry and shift
       btfsc  STATUS,C     ;if negative
       bsf    file,7       ;set the sign bit
ASR can be done with,
Code:
      rlf   file,w         ;move sign bit into carry
      rrf   file,f         ; and then into bit 7

Edit, just realised the OP is talking any processor. Well, in that case most have the arithmetic version.

Mike.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…