# `clz`

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

Web page: https://asm-editor.specy.app/documentation/mips/instruction/clz

**Count leading zeros**

Category: Logic

Sets the first register to the number of consecutive 0 bits in the second, counted from the most-significant bit downward.

Used in: [Masks, shifts, popcount, and leading zeroes](https://asm-editor.specy.app/learn/courses/mips/examples/bit-tricks.md) (MIPS assembly)

## Forms

- `clz $t1, $t2`

## Operands

- `$t1`: Any general-purpose register, `$0` to `$31`, using its numeric or named spelling, such as `$8` or `$t0` (`$zero` is `$0`; `$ra` is `$31`).
- `$t2`: A general-purpose register. It may be the same register as `$t1`.

## Description

For example, if $t2 = 0b00010000..., then $t1 = 3. Returns 32 if $t2 is 0. Often used to compute floor(log2(n)) or to normalize values.

## Example

```mips
# Apply clz to initialized pattern 0x00F0FF00. Inspect $t2: 8.
li $t0, 0x00F0FF00
clz $t2, $t0
```
