# `jr`

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

**Jump relative**

Category: Control flow

Jumps to a target up to 128 bytes away, either always or only when a flag condition is met.

12/7 cycles: 12 when it jumps, 7 when it does not

Used in: [jp, jr and the conditions](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/jp-jr-and-the-conditions.md) (Z80 assembly), [Loops and djnz](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/loops-and-djnz.md) (Z80 assembly), [Arrays, strings and ix](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/arrays-strings-and-ix.md) (Z80 assembly), [call, ret and passing values](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/call-ret-and-passing-values.md) (Z80 assembly), [Ports: in and out](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/ports-in-and-out.md) (Z80 assembly), [The screen, keyboard and mouse through ports](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/screen-keyboard-and-mouse.md) (Z80 assembly), [Interrupts: im, ei, di and halt](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/interrupts-im-ei-di-and-halt.md) (Z80 assembly), [The bigger of two numbers](https://asm-editor.specy.app/learn/courses/z80/examples/if-else.md) (Z80 assembly), [The largest element](https://asm-editor.specy.app/learn/courses/z80/examples/max-of-an-array.md) (Z80 assembly), [Length of a string](https://asm-editor.specy.app/learn/courses/z80/examples/string-length.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | not changed |
| Z | not changed |
| H | not changed |
| P/V | not changed |
| N | not changed |
| C | not changed |

## Forms

- `jr offset` · 2 bytes · 12 cycles · The signed value `offset` is added to PC. The jump is measured from the start of the instruction opcode.

- `jr cc, offset` · 2 bytes · 12/7 cycles · cc: nz z nc c · If the condition `cc` is true, the signed value `offset` is added to PC. The jump is measured from the start of the instruction opcode.
  - `jr nz, offset`
  - `jr z, offset`
  - `jr nc, offset`
  - `jr c, offset`

## Operands

- [`offset`](https://asm-editor.specy.app/documentation/z80/registers/operand-offset.md): A relative-jump target, written as a label or address. The assembler calculates the displacement, `-128` to `127`, and reports an error if the target is out of range.
- [`cc`](https://asm-editor.specy.app/documentation/z80/registers/operand-cc.md): A flag condition: `nz` (zero flag clear, `Z = 0`), `z` (zero flag set, `Z = 1`), `nc` (carry flag clear, `C = 0`) or `c` (carry flag set, `C = 1`). Here `c` tests the carry flag; it does not name the `c` register.

## Example

```z80
        .org 0x8000
        jr target
target: halt
```
