What is jz in assembly language

Last updated: April 1, 2026

Quick Answer: JZ is an x86 assembly language instruction that stands for "Jump if Zero." It conditionally jumps to a specified memory address if the zero flag is set to 1, typically after a comparison or arithmetic operation.

Key Facts

JZ Instruction Overview

The JZ instruction is a fundamental conditional jump instruction in x86 and x64 assembly language. It allows programmers to create branching logic based on the state of the CPU's zero flag, enabling programs to make decisions and control program flow.

How JZ Works

The JZ instruction checks the zero flag (ZF), which is part of the EFLAGS register. When the zero flag is set to 1, the instruction jumps to the specified target address. If the zero flag is 0, execution continues with the next instruction sequentially. The zero flag is automatically set or cleared by arithmetic and logical operations.

Common Usage Patterns

JZ is typically used after a comparison instruction (CMP) to test if two values are equal. For example, after "CMP EAX, 0", a JZ instruction will jump if EAX contains zero. This pattern is used extensively in loops, conditional branching, and error checking routines.

JZ vs JE Equivalence

The JZ and JE (Jump if Equal) instructions are functionally identical. Both check the zero flag and jump when it equals 1. The mnemonics differ because JZ emphasizes testing for zero results, while JE emphasizes testing for equal values. Assemblers recognize both as the same instruction.

Practical Examples

A typical usage is: CMP ECX, EDX followed by JZ equal_label, which jumps to equal_label if ECX and EDX are equal. Another common pattern is testing array bounds: CMP index, array_length followed by JZ exit_loop to exit when the condition is met.

Related Questions

What is the difference between JZ and JNZ instructions?

JZ jumps when the zero flag is set (value equals zero), while JNZ jumps when the zero flag is clear (value is non-zero). They provide opposite conditional logic for branching decisions.

What are CPU flags and how do they work?

CPU flags are individual bits in the EFLAGS register that store the results of operations. Common flags include the zero flag, carry flag, and sign flag, which control conditional instructions and program flow.

How do comparison instructions work in assembly?

The CMP instruction subtracts one operand from another and sets CPU flags based on the result without storing the result. This allows subsequent conditional jumps to make decisions based on the comparison outcome.

Sources

  1. Wikipedia - X86 Instruction Listings CC-BY-SA-4.0
  2. Intel 64 and IA-32 Architectures Software Developer Manual All Rights Reserved