I'm a bit of an optimizer, so here is my move using the syntax that I'm most familiar with (from TASM assembler, etc.):
Instruction opcode timing ld bc,$EE9D ;01EE9D 10cc ex (sp),hl ;E3 19*(256C+B) ex (sp),hl ;E3 19*(256C+B) ex (sp),hl ;E3 19*(256C+B) ex (sp),hl ;E3 19*(256C+B) djnz $ ;10FA 13cc*(256C+B) - 5*C dec c ;0D 4*C jr nz,$-3 ;20F7 12*C-5
This code is 12 bytes and 3600002 clock cycles.
EDIT . It seems like part of my answer is gone! To better answer your question, your Z80 can process 1800000 clock cycles in one second, so you need twice as much (3600000). If you add the timings indicated in my code, you will receive:
= 10 + (256C + V) (19 * 4 + 13) -5C + 4C + 12C-5
= 5 + (256C + V) 89 + 11C
= 5 + 22795C + 89B
Thus, the code time largely depends on C. 3600000/22795 - about 157, so we initialize C with 157 (0x9D). Inserting this back, we get B about 237.9775, so we round up to 238 (0xEE). When connecting these devices, we get a final time of 3600002cc or about 2.000001 seconds. This suggests that the processor runs at exactly 1.8 MHz, which is very unlikely.
Also, if you can use interrupts, find out how many times it fires per second, and use a loop like halt \ djnz $-1 . This saves a lot more in terms of energy consumption.
source share