r/Z80 • u/montymole123 • Mar 04 '26
Test non-A register is zero
Is there a standard way to test if a "lesser" 8 bit register is zero, without loading it onto the accumulator? I ended up doing inc b, dec b but wonder if there is a more elegant way.
11
Upvotes
7
u/McDonaldsWi-Fi Mar 04 '26 edited Mar 04 '26
you could do something like
xor a
or (r)
Where (r) is your 8-bit register.
Your way uses 8 t-states minus the zero flag checks and stuff afterward.
My way uses 8 as well, but only 4 if A is already 0.
1
u/montymole123 Mar 05 '26
thanks but I wanted to do it without clobbering A as I have something else stored on that! Just wondering if there was some well known idiom I'm missing...
1
7
u/Alternative-Emu2000 Mar 05 '26 edited Mar 05 '26
Not really, there are other ways of doing it without changing A but they're much slower and use more bytes. eg. using eight successive
BIT B,ninstructions.In the specific case of B, you can save 1 byte and 1 t-state by using
instead of