Showing posts with label Instruction-Rotate. Show all posts
Showing posts with label Instruction-Rotate. Show all posts

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

Monday, May 17, 2010

Shifting & Rotating

Question
Complete the following program so that at the end, AL will equal to FC and CF=1. Use only SHL followed by SAR AL,3 and finally RCR instruction.


MOV AL,33h // AL = 33h , initial CF=0
SHL ________
SAR AL,3 // CF-AL = 1-1111 1001
RCR ________

Answer

MOV AL,33H CF,AL : 0 0011 0011

SHL AL, 2 ; CF,AL : 0 1100 1100
SAR AL, 3 ; CF,AL : 1 1111 1001
RCR AL, 2 ; CF,AL : 0 1100 1100

Tuesday, May 11, 2010

Rotating & Shifting tutorial

Question
Calculate the changes in AX and CF for each of the instruction in the program below (Assume initial CF=0)

MOV AX, F0h
SHL AH,3
SAR AH,4
RCR AH,1
OR   AH,AL

Answer

MOV AX, F0h
--> AX = 0000 0000 | 1111 0000
--> CF = 0


SHL AH,3
--> AH = 0000 0000 , shift to left 3 times will equal to 0000 0000 (no changes)
--> AX = 0000 0000 | 1111 0000
--> CF = 0



SAR AH,4
--> AH = 0000 0000 , shift arithmetic to right 3 times will make AH equal to 0000 0000 (no changes)

--> AX = 0000 0000 | 1111 0000
--> CF = 0

RCR AH,1
--> AH = 0000 0000 , shift with carry to right 1 times will make AH equal to 0000 0000 (no changes) and CF equal to zero
--> AX = 0000 0000 | 1111 0000
--> CF = 0


OR AH,AL
--> AH = 0000 0000
--> AL =  1111 0000
--> OR AH,AL --> AH = AH OR AL = 1111 0000 (F0h) --> AX = F0F0h , CF = 0


ROL AL,3
--> AL=11110000, rotate to left 3 times will make AL equal to 1000 0111 (87h)
--> AX = F087h, CF=1

Popular Posts

Latest Post from my Other Blog