Shift and Rotate Instructions Module M 16 2

  • Slides: 12
Download presentation
Shift and Rotate Instructions Module M 16. 2 Section 10. 3 Introduction to Computer

Shift and Rotate Instructions Module M 16. 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

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

Shift Left: SHL AL, 1 Introduction to Computer Engineering by Richard E. Haskell

11100 000 = E 0 SHL AL, 1 D 0 E 0 Introduction to

11100 000 = E 0 SHL AL, 1 D 0 E 0 Introduction to Computer Engineering by Richard E. Haskell

D 0 E 0 SHL AL, 1 Tutor: /MH D 0 E 0 D

D 0 E 0 SHL AL, 1 Tutor: /MH D 0 E 0 D 0 E 0 Introduction to Computer Engineering by Richard E. Haskell

Shift Right: SHR Bit 0 7 6 5 4 3 2 1 0 1

Shift Right: SHR Bit 0 7 6 5 4 3 2 1 0 1 0 0 1 Introduction to Computer Engineering by Richard E. Haskell C 1

Rotate through Carry Left: RCL C 1 Bit 7 6 1 0 5 1

Rotate through Carry Left: RCL C 1 Bit 7 6 1 0 5 1 4 3 0 2 0 1 0 Introduction to Computer Engineering by Richard E. Haskell 1

Rotate through Carry Right: RCR Bit 7 6 1 0 5 1 4 3

Rotate through Carry Right: RCR Bit 7 6 1 0 5 1 4 3 0 2 0 1 0 C 1 Introduction to Computer Engineering by Richard E. Haskell 1

Rotate Left and Rotate Right: ROL and ROR ROL C 1 1 0 0

Rotate Left and Rotate Right: ROL and ROR ROL C 1 1 0 0 1 (a) ROR 1 0 0 C 1 0 1 (b) Introduction to Computer Engineering by Richard E. Haskell 1

Shift Arithmetic Right: SAR C 1 0 0 1 1 1 0 1 1

Shift Arithmetic Right: SAR C 1 0 0 1 1 1 0 1 1 0 1 0 0 1 0 Introduction to Computer Engineering by Richard E. Haskell

Use CL to shift multiple bits 0000 0002 B 1 03 D 2 E

Use CL to shift multiple bits 0000 0002 B 1 03 D 2 E 0 MOV CL, 3 SHL AL, CL AL = 5 = 00000101000 shift left 3 bits = 28 H = 40 = 5 x 23 = 5 x 8 Shifting left 1 bit multiplies by 2 Introduction to Computer Engineering by Richard E. Haskell

Shifting right 1 bit divides by 2 0000 0002 B 1 03 D 2

Shifting right 1 bit divides by 2 0000 0002 B 1 03 D 2 E 8 MOV CL, 3 SHR AL, CL AL = 10010 = 64 H = 01100100 00001100 shift right 3 bits = 0 CH = 12 = 100 / 23 = 100 / 8 8 x 12 = 96 Note: Remainder of 4 = 1002 is shifted out and lost. Introduction to Computer Engineering by Richard E. Haskell