# `shld`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/shld

**Integer double precision shift left**

Category: Shifts and rotates

Performs a double-precision left shift, filling the vacated low bits of the destination with high bits from the source (second) operand.

386 and later

[Intel's reference: SHLD](https://intel.github.io/SDM/instruction/SHLD.html)

## Flags

| Flag | Effect |
| --- | --- |
| CF | depends on the result |
| PF | depends on the result |
| AF | undefined (do not rely on it) |
| ZF | depends on the result |
| SF | depends on the result |
| DF | not changed |
| OF | undefined (do not rely on it). Defined only for a count of 1. |

A count of 0 leaves every flag unchanged. A 16-bit operand shifted by more than 16 leaves every flag undefined.

## Forms

- `shld r/m, reg, imm8` (16, 32, 64)
  - `shld r/m16, reg16, imm8`
  - `shld r/m32, reg32, imm8`
  - `shld r/m64, reg64, imm8`
- `shld r/m, reg, cl` (16, 32, 64)
  - `shld r/m16, reg16, cl`
  - `shld r/m32, reg32, cl`
  - `shld r/m64, reg64, cl`

## Operands

- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.
- `reg`: A general-purpose register matching the operation’s size, for example `al`, `ax`, `eax` or `rax`.
- `imm8`: An 8-bit immediate, `-128` to `255`. Instructions that sign-extend it to a wider operand interpret the byte as `-128` to `127`; shift counts do not use this sign extension.

## Description

`shld` shifts left and fills the low end from the source's high end; `shrd` shifts right and fills the high end from the source's low end. Only the first operand changes. For example, with `eax = 0x01234567` and `ebx = 0x89abcdef`, `shld eax, ebx, 4` leaves `eax = 0x12345678`.

The third operand is an immediate or `cl`. Its low six bits are used for 64-bit operands and its low five for 16- and 32-bit operands. A masked count of zero leaves the destination and flags unchanged; a count greater than the operand width has an undefined result.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        shld rax, rbx, 5

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
