cnttzw

Count Trailing Zeros Word

cnttzw RA, RS

Counts the number of trailing zeros in the low 32-bits.

Details

Counts the number of trailing zero bits in the low 32 bits of general-purpose register RS and stores the count in RA. The count ranges from 0 to 32; if all 32 bits are zero, the result is 32. No condition register or status flags are affected.

Pseudocode Operation

count ← 0
for i in 0..31:
  if RS[32+i] == 0 then count ← count + 1
  else break
RA ← count

Programming Note

The cnttzw instruction is useful for quickly determining the number of trailing zeros in a word, which can be helpful in bit manipulation tasks. Be cautious with Rc=1 as it modifies CR0 based on the result, affecting subsequent conditional operations. Ensure that the input register (RS) is correctly aligned and contains valid data to avoid unexpected results.

Example

cnttzw r4, r3

Encoding

Binary Layout
31
0
RS
6
RA
11
/
16
538
21
/
31
 
Format X-form
Opcode 0x7C000434
Extension Base
Registers Altered CR0

Operands

  • RA
    Target
  • RS
    Source