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

No comments:

Post a Comment

Popular Posts

Latest Post from my Other Blog