# `js`

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

**Jump if sign (SF == 1)**

Category: Control flow

Jumps to the target when the sign flag is set (SF is 1).

8086 and later

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

Used in: [syscall and the Linux x86-64 ABI](https://asm-editor.specy.app/learn/courses/x86/talking-to-the-outside-world/syscall-and-the-linux-abi.md) (x86-64 assembly), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/x86/examples/drawing-on-the-screen.md) (x86-64 assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/x86/examples/bouncing-ball.md) (x86-64 assembly), [Move a square with the keyboard](https://asm-editor.specy.app/learn/courses/x86/examples/keyboard-control.md) (x86-64 assembly), [Paint with the mouse](https://asm-editor.specy.app/learn/courses/x86/examples/mouse-paint.md) (x86-64 assembly), [Beep a tune on the PC speaker](https://asm-editor.specy.app/learn/courses/x86/examples/pc-speaker.md) (x86-64 assembly), [Play a tune](https://asm-editor.specy.app/learn/courses/x86/examples/play-a-tune.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 | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

Reads: SF

## Forms

- `js short imm8`
- `js imm`
- `js near imm32` · 386 and later

## Operands

- `imm8`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. The displacement must fit a signed byte, `-128` to `127`.
- `imm`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. NASM selects a short or near encoding according to the target’s reach and any size constraint.
- `imm32`: A branch target, written as a label or address. NASM calculates the displacement from the end of the instruction. In 64-bit mode the encoded displacement is signed 32-bit, `-2147483648` to `2147483647`, even though the target address is 64-bit.

## Description

The condition reads the current flags, commonly set by `cmp` or `test`. Signed comparisons use SF and OF; unsigned comparisons use CF. The [condition-code table](https://asm-editor.specy.app/documentation/x86/registers/condition-codes.md) lists the flag tests and synonymous mnemonics.

Write the target label or address, such as `jne retry`. NASM calculates a displacement from the end of the jump. The short form reaches −128 through 127 bytes from that point; the longer near form in 64-bit mode uses a signed 32-bit displacement (about ±2 GiB). NASM normally selects the short form when possible. `short` requires the short range, while `strict near` keeps the longer form.

Conditional jumps have no register or memory-indirect target form. To conditionally reach an arbitrary 64-bit address, branch around an indirect `jmp`.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        cmp rax, 12         ; sets the flags the condition reads
        js taken
        mov rbx, 1          ; runs when the condition is false
        jmp done
taken:
        mov rbx, 2          ; runs when it is true
done:

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