Pages

Search in This Blog

Sunday 15 January 2012

shift instrcuctions


SHIFT INSTRUCTIONS

 SAL/SHL Instruction - Shift operand bits left, put zero in LSB(s)
SAL instruction shifts the bits in the operand specified by op1 to its left by the count specified in op2. As a bit is shifted out of LSB position a 0 is kept in LSB position. CF will contain MSB bit.

Syntax - SAL/AHL destination, count

Example:
                                            ;CF = 0, BX = 11100101 11010011
SAL BX, 1                               ;Shift BX register contents by 1 bit position towards left
                                            ;CF = 1, BX = 11001011 1010011

  • SHR Instruction - Shift operand bits right, put zero in MSB
SHR instruction shifts the bits in op1 to right by the number of times specified by op2 .

Example:( 1 )
SHR BP, 1                             ; Shift word in BP by 1 bit position to right and 0 is kept to MSB

Example:( 2 )
MOV CL, 03H                        ;Load desired number of shifts into CL
SHR BYTE PYR[BX]                ;Shift bytes in DS at offset BX and rotate 3 bits to right and keep 3 0’s in MSB

Example:( 3 )
                                           ;SI = 10010011 10101101 , CF = 0
SHR SI, 1                             ; Result: SI = 01001001 11010110 and CF = 1, OF = 1, SF = 0, ZF = 0

  • SAR Instruction - Shift operand bits right, new MAB = old MSB
SAR instruction shifts the bits in the operand specified by op1 towards right by count specified in op2.As bit is shifted out a copy of old MSB is taken in MSB. MSB position and LSB is shifted to CF.
Syntax - SAR destination, count.

Example: ( 1 )
                                         ; AL = 00011101 = +29 decimal, CF = 0
SAR AL, 1                           ;Shift signed byte in AL towards right ( divide by 2 )
                                         ;AL = 00001110 = + 14 decimal, CF = 1

Example: ( 2 )
                                      ;BH = 11110011 = - 13 decimal, CF = 1
SAR BH, 1                        ;Shifted signed byte in BH to right and BH = 11111001 = - 7 decimal, CF = 1.

No comments:

Post a Comment