The Sinclair “ZX” family of machines used a Z80 processor. Technically speaking a Z80A which the Sinclair manuals liked saying “goes faster”.
The Z80 is actually a rather powerful CPU by 8-bit standards, having six general purpose 8-bit registers (B, C, D, E, H and L) which could be paired up to make virtual 16-bit registers (BC, DE and HL), two 16-bit index registers (IX and IY) and a ‘flags’ register (F) in addition to the accumulator (A). All of these (with the exception of the index registers) also had alternate or shadow versions.
For the most part any “math” or “logic” operations worked on the contents of the accumulator, A.
So, let’s put zero into A…
LD A,0
Well you COULD do that. It works. You don’t tend to see it that often.
XOR A
For those that don’t know, an XOR operation takes each bit in turn, and produces a zero if both bits are the same, and one if the bits are different. If you XOR something with itself the result is zero as all bits are the same. Thus XOR A produces zero in the accumulator, though at the expense of changing the CPU flags, notably the zero flag in this case.
Now, in BASIC, performing math to produce zero (NOT PI, see previous post) is slower but shorter, what about Z80 code?
Well the LD A,0 instruction is two bytes long, and takes 7 clock cycles to complete (in theory). In comparison XOR A is only one byte in length and a timing of only 4 clock cycles. XOR A is faster AND shorter! Win win!