# `shl`

[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/shl

**Logical shift left**

Category: Shifts and rotates

Shifts the destination (first) operand left by the given count, filling the vacated low bits with zeros.

8086 and later

[Intel's reference: SAL/SAR/SHL/SHR](https://intel.github.io/SDM/instruction/SAL-SAR-SHL-SHR.html)

Used in: [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arithmetic-logic-and-bits.md) (x86-64 assembly), [Even or odd, count the set bits, multiply by shifting](https://asm-editor.specy.app/learn/courses/x86/examples/bit-tricks.md) (x86-64 assembly), [Sampled sound](https://asm-editor.specy.app/learn/courses/x86/examples/sampled-sound.md) (x86-64 assembly)

## 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.

## Forms

- `shl r/m, imm8` (8, 16, 32, 64)
  - `shl r/m8, imm8`: 186 and later
  - `shl r/m16, imm8`: 186 and later
  - `shl r/m32, imm8`: 386 and later
  - `shl r/m64, imm8`
- `shl r/m, 1` (8, 16, 32, 64)
  - `shl r/m8, 1`
  - `shl r/m16, 1`
  - `shl r/m32, 1`: 386 and later
  - `shl r/m64, 1`
- `shl r/m, cl` (8, 16, 32, 64)
  - `shl r/m8, cl`
  - `shl r/m16, cl`
  - `shl r/m32, cl`: 386 and later
  - `shl r/m64, cl`

## Operands

- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.
- `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

`shl` and its synonym `sal` shift left and fill low bits with zeros. `shr` shifts right and fills high bits with zeros; `sar` shifts right and repeats the original sign bit. When defined, CF receives the last bit shifted out. OF is defined only for a count of one; CF is undefined for a `shl` or `shr` count at least as large as the operand width.

The count comes from an immediate or `cl`. A 64-bit operand uses the low six bits of the count; 8-, 16- and 32-bit operands use the low five. Thus `shl rax, 32` shifts by 32, while `shl eax, 32` has a masked count of zero.

## Example

```x86
global _start

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

        shl rax, 1

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