Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Can shift bytes or words in registers or memory left or right 1 bit. Can rotate or rotate through carry bytes or words in registers or memory left or right 1 bit. Can shift bytes or words in registers or memory left or right CL bits. Can rotate or rotate through carry bytes or words in registers or memory left or right CL bits.
Introduction to Computer Engineering by Richard E. Haskell Shift Left: SHL AL,1
Introduction to Computer Engineering by Richard E. Haskell SHL AL,1 100 D = E0 E0
Introduction to Computer Engineering by Richard E. Haskell D0 E0 SHL AL,1 Tutor: /MH D0 E0 D0 E0 D0 E0 D0 E0 D0 E0 D0 E0 D0 E0 D0 E0
Introduction to Computer Engineering by Richard E. Haskell Shift Right: SHR C Bit
Introduction to Computer Engineering by Richard E. Haskell Rotate through Carry Left: RCL C Bit
Introduction to Computer Engineering by Richard E. Haskell Rotate through Carry Right: RCR C Bit
Introduction to Computer Engineering by Richard E. Haskell Rotate Left and Rotate Right: ROL and ROR C ROR C ROL (a) (b)
Introduction to Computer Engineering by Richard E. Haskell Shift Arithmetic Right: SAR C
Introduction to Computer Engineering by Richard E. Haskell Use CL to shift multiple bits 0000 B1 03 MOV CL, D2 E0 SHL AL,CL AL = 5 = shift left 3 bits = 28H = 40 = 5 x 2 3 = 5 x 8 Shifting left 1 bit multiplies by 2
Introduction to Computer Engineering by Richard E. Haskell Shifting right 1 bit divides by B1 03 MOV CL, D2 E8 SHR AL,CL AL = = 64H = shift right 3 bits = 0CH = 12 = 100 / 2 3 = 100 / 8 8 x 12 = 96 Note: Remainder of 4 = is shifted out and lost.