What is jz in assembly language
Last updated: April 1, 2026
Key Facts
- JZ is a conditional jump instruction in x86/x64 assembly architecture
- The instruction jumps to a target address only if the zero flag (ZF) equals 1
- JZ is commonly used after CMP (compare) or arithmetic instructions like SUB or ADD
- JZ has an equivalent instruction called JE (Jump if Equal) with identical behavior
- The zero flag is set when an operation produces a result of zero
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.
More What Is in Language
Also in Language
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Wikipedia - X86 Instruction ListingsCC-BY-SA-4.0
- Intel 64 and IA-32 Architectures Software Developer ManualAll Rights Reserved