Slide 16.1: Shift and rotate instructions
Slide 16.3: SHR instruction
Home

SAL/SHL Instruction


The SAL (shift arithmetic left) or SHL (shift left) instruction performs a logical left shift on the destination operand, filling the lowest bit with 0. The highest bit is moved to the Carry flag, and the bit that was in the Carry flag is lost.

 SAL/SHL — Shift Arithmetic Left / Shift Logical Left 
Usage: SAL dest, count or SHL dest, count


Flag O D I S Z A P C
Result *     * * ? * *


Shifts the destination left by “count” bits with zeroes shifted in on right. The Carry flag contains the last bit shifted out.
Clocks
Operands 286 386 486 Size Bytes
reg, 1 2 3 3 2
mem, 1 7 7 4 2-4
reg, CL 5+n 3 3 2
mem, CL 8+n 7 4 2-4
reg, immed8 5+n 3 2 3
mem, immed8 8+n 7 4 3-5

One of the best uses of SAL/SHL is for performing high-speed multiplication by powers of 2. Shifting any operand left by n bits multiplies the operand by 2n.

 Shift Positive Left   Shift Negative Left   Shift Arithmetic Left 
 .data
 value  BYTE  4
 .code
 shl    value, 03
 movsx  eax, value
 call   WriteInt
 .data
 value  BYTE  -16
 .code
 shl    value, 03
 movsx  eax, value
 call   WriteInt
 .data
 value  BYTE  -17
 .code
 sal    value, 03
 movsx  eax, value
 call   WriteInt
 Output  Output  Output
  EAX =

 

  EAX =

 

  EAX =