shld
Double Precision Shift Left
Shifts dest left, filling with bits from src.
Details
Shifts the destination operand left by a count, filling the vacated bits from the most-significant bits of the source operand. Supports 16/32/64-bit operands; count comes from the immediate or implicitly from CL. Sets CF to the last bit shifted out, OF if count=1, SF/ZF/PF based on the result.
Pseudocode Operation
if count > operand_width:
count ← count mod (operand_width + 1)
if count == 0:
skip
else:
CF ← bit_shifted_out_from_left
dest ← (dest << count) | (src >> (operand_width - count))
if count == 1:
OF ← (dest_sign_bit_after != CF)
else:
OF ← undefined
ZF ← (dest == 0)
SF ← (dest_sign_bit == 1)
PF ← popcount(dest & 0xFF) is even
Example
Encoding
Operands
-
dest
Reg/Mem -
fill
Reg -
count
Imm
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| 0F A4 /r ib | SHLD r/m16, r16, imm8 | MRI | Valid Valid | Shift r/m16 to left imm8 places while shifting bits from r16 in from the right. | |
| 0F A5 /r | SHLD r/m16, r16, CL | Valid Valid | MRC | Shift r/m16 to left CL places while shifting bits from r16 in from the right. | |
| 0F A4 /r ib | SHLD r/m32, r32, imm8 | MRI | Valid Valid | Shift r/m32 to left imm8 places while shifting bits from r32 in from the right. | |
| REX.W + 0F A4 /r ib | SHLD r/m64, r64, imm8 | MRI | Valid N.E. | Shift r/m64 to left imm8 places while shifting bits from r64 in from the right. | |
| 0F A5 /r | SHLD r/m32, r32, CL | Valid Valid | MRC | Shift r/m32 to left CL places while shifting bits from r32 in from the right. | |
| REX.W + 0F A5 /r | SHLD r/m64, r64, CL | Valid N.E. | MRC | Shift r/m64 to left CL places while shifting bits from r64 in from the right. |
Description
Operation
IF (In 64-Bit Mode and REX.W = 1) THEN COUNT := COUNT MOD 64; ELSE COUNT := COUNT MOD 32; FI SIZE := OperandSize; tempDEST := DEST; IF COUNT > SIZE THEN (* Bad parameters *) tempDEST is undefined; SHLD—Double Precision Shift Left Vol. 2B 4-639 CF, OF, SF, ZF, AF, PF are undefined; ELSE IF COUNT > 0 (* Perform the shift *) CF := BIT[tempDEST, SIZE – COUNT]; (* Last bit shifted out on exit *) FOR i := SIZE – 1 DOWN TO COUNT DO Bit(tempDEST, i) := Bit(tempDEST, i – COUNT); OD; FOR i := COUNT – 1 DOWN TO 0 DO BIT[tempDEST, i] := BIT[SRC, i – COUNT + SIZE]; OD; FI; DEST := tempDEST;
Flags Affected
If the count is 1 or greater, the CF flag is filled with the last bit shifted out of the destination operand and the SF, ZF, and PF flags are set according to the value of the result. For a 1-bit shift, the OF flag is set if a sign change occurred; otherwise, it is cleared. For shifts greater than 1 bit, the OF flag is undefined. If a shift occurs, the AF flag is undefined. If the count operand is 0, the flags are not affected. If the count is greater than the operand size, the flags are undefined.