# `rl`

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

Web page: https://asm-editor.specy.app/documentation/z80/instruction/rl

**Rotate left through carry**

Category: Shifts and rotates

Rotates a register or memory byte left one bit, moving C into bit 0 and bit 7 into C.

Used in: [8-bit and 16-bit arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/arithmetic-logic-and-bits.md) (Z80 assembly), [Multiply and divide, with the remainder](https://asm-editor.specy.app/learn/courses/z80/examples/multiply-and-divide.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | set from the result |
| Z | set from the result |
| H | always 0 |
| P/V | holds the parity of the result |
| N | always 0 |
| C | set from the result |

## Forms

- `rl r` · 2 bytes · 8 cycles · The contents of `r` are rotated left one bit position. The contents of bit 7 are copied to the carry flag and the previous contents of the carry flag are copied to bit 0.
  - `rl b`
  - `rl c`
  - `rl d`
  - `rl e`
  - `rl h`
  - `rl l`
  - `rl a`

- `rl (hl)` · 2 bytes · 15 cycles · The contents of (HL) are rotated left one bit position. The contents of bit 7 are copied to the carry flag and the previous contents of the carry flag are copied to bit 0.

- `rl (ix+dd)` · 4 bytes · 23 cycles · The contents of the memory location pointed to by IX plus `dd` are rotated left one bit position. The contents of bit 7 are copied to the carry flag and the previous contents of the carry flag are copied to bit 0.
  - `rl (ix+dd)`
  - `rl (iy+dd)`

## Undocumented

Left out of Zilog's manual, but the Z80 runs them, and so does this emulator.

- `rl (ix+dd), r` · 4 bytes · 23 cycles · The contents of the memory location pointed to by IX plus `dd` are rotated left one bit position. The contents of bit 7 are copied to the carry flag and the previous contents of the carry flag are copied to bit 0. The result is then stored in `r`.
  - `rl (ix+dd), b`
  - `rl (ix+dd), c`
  - `rl (ix+dd), d`
  - `rl (ix+dd), e`
  - `rl (ix+dd), h`
  - `rl (ix+dd), l`
  - `rl (ix+dd), a`
  - `rl (iy+dd), b`
  - `rl (iy+dd), c`
  - `rl (iy+dd), d`
  - `rl (iy+dd), e`
  - `rl (iy+dd), h`
  - `rl (iy+dd), l`
  - `rl (iy+dd), a`

## Operands

- `r`: An 8-bit register: `a`, `b`, `c`, `d`, `e`, `h` or `l`.
- [`(hl)`](https://asm-editor.specy.app/documentation/z80/registers/operand-hl.md): The byte in memory at the address stored in `hl`.
- [`(ix+dd)`](https://asm-editor.specy.app/documentation/z80/registers/operand-ix-dd.md): The byte in memory at `ix + dd`, where `dd` is a signed displacement from `-128` to `127`, for example `(ix+5)` or `(ix-3)`. `(iy+dd)` works the same way.

## Example

```z80
        .org 0x8000
        ld b, 3
        rl b
        halt
```
