Wednesday, May 19, 2010

Shifting & Rotating

Question
Calculate the changes in AL by each of the instruction below. (AH=33h,CF=0 and each instruction is not related to each other)
i.    RCR AL,2
ii.    SHL AL, 2    
iii.    SAR AL,2    

Answer

i.    RCR AL,2
AH=01110111 CF=0
rotate with carry to the right two times
AH = 10011101 CF=1
Answer >> AH = 9D16 CF=1

ii.    SHL AL, 2    
AH=01110111 CF=0
shift to the left two times
AH = 11011100 CF=0
Answer >> AH= DC16 CF=0

iii.    SAR AL,2    
AH=01110111 CF=0
shift arithmetic to the right two times (if the sign bit is one, then number 1 will be shifted into the stream, if not zero will be inserted, in this case the sign bit is 0 so zero will be inserted)
AH= 00011101 CF=0
Answer >> AH= 1D16 CF=0

1 comment:

  1. the answer for ii and iii is wrong. the carry flag should be CF=1.
    the reason is whenever SHL/SHR/SAL/SAR/ROL/ROR is used, the last bit of the action is copied over to the CF and replace the old value of CF.

    ii) SHL AL, 2
    AH=01110111 CF=0
    shift to the left two times
    AH = 11011100 CF=1

    iii) SAR AL,2
    AH=01110111 CF=0
    shift arithmetic to the right two times
    AH= 00011101 CF=1

    ReplyDelete

Popular Posts

Latest Post from my Other Blog