Ch 7 8 9 Slides_10 - Click to edit Master subtitle style...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style 9/8/10 Irvine, Kip R. Assembly CmpE 102 Chapter 7, 8 & 9 Slides Frank Cirimele 11 9/8/10 Irvine, Kip R. Assembly 22 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 33 Logical vs Arithmetic Shifts A logical shift fills the newly created bit position with zero: • An arithmetic shift fills the newly created bit position with a copy of the number’s sign bit: CF CF 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 44 SHL Instruction The SHL (shift left) instruction performs a logical left shift on the destination operand, filling the lowest bit with . CF • Operand types for SHL: SHL reg,imm8 SHL mem,imm8 SHL reg ,CL SHL mem ,CL (Same for all shift and rotate instructions) 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 55 Fast Multiplication mov dl,5 shl dl,1 Shifting left 1 bit multiplies a number by 2 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 = 5 = 10 Before: After: mov dl,5 shl dl,2 ; DL = 20 Shifting left n bits multiplies the operand by 2 n For example, 5 * 22 = 20 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 66 SHR Instruction The SHR (shift right) instruction performs a logical right shift on the destination operand. The highest bit position is filled CF mov dl,80 shr dl,1 ; DL = 40 shr dl,2 ; DL = 10 Shifting right n bits divides the operand by 2 n 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 77 SAL and SAR Instructions SAL (shift arithmetic left) is identical to SHL. SAR (shift arithmetic right) performs a right CF An arithmetic shift preserves the number's sign. mov dl,-80 sar dl,1 ; DL = -40 sar dl,2 ; DL = -10 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 88 ROL Instruction ROL (rotate) shifts each bit to the left The highest bit is copied into both the Carry flag and into the lowest bit No bits are lost CF mov al,11110000b rol al,1 ; AL = 11100001b mov dl,3Fh rol dl,4 ; DL = F3h 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 99 ROR Instruction ROR (rotate right) shifts each bit to the right The lowest bit is copied into both the Carry flag and into the highest bit CF mov al,11110000b ror al,1 ; AL = 01111000b mov dl,3Fh ror dl,4 ; DL = F3h 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 1010 RCL Instruction RCL (rotate carry left) shifts each bit to the left Copies the Carry flag to the least significant bit CF clc ; CF = 0 mov bl,88h ; CF,BL = 0 10001000b rcl bl,1 ; CF,BL = 1 00010000b rcl bl,1 ; CF,BL = 0 00100001b 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 1111 RCR Instruction RCR (rotate carry right) shifts each bit to the right Copies the Carry flag to the most significant bit stc ; CF = 1 mov ah,10h ; CF,AH = 1 00010000b rcr ah,1 ; CF,AH = 0 10001000b CF 9/8/10 Irvine, Kip R. Assembly Irvine, Kip R. Assembly 1212 Application: Shifting Multiple Doublewords Programs sometimes need to shift all bits within an array, as one might when moving a bitmapped graphic image from one...
View Full Document

This note was uploaded on 09/08/2010 for the course CMPE 46 at San Jose State University .

Page1 / 66

Ch 7 8 9 Slides_10 - Click to edit Master subtitle style...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online