title: Z80 Software Delay
body: <p>I am trying to create a software delay. Here is a sample program of what I am doing:</p>
  
  <pre><code>    Address  Data   Opcode  Comment    
      1800      06    LD, B   Load register B with fix value
      1801      “ “           Fixed value
      1802      05    DEC, B  Decrement value in register B
      1803      C2    JP cc   Jump to 1802 if value is not 0
      1804      02    -       Address XX
      1805      18    -       Address XX
  </code></pre>
  
  <p>My question is how can I calculate the required fixed value to load into register B so that the process of decrementing the value until 0 takes 2 seconds?</p>
  
  <p>In my manual the time given to run the instructions is based on a 4MHz CPU but the Z80 CPU I am using has a speed of 1.8MHz. Any idea how I can calculate this? Thanks. P.S here is the decrement (DEC) and jump (JP cc) instructions from the manual:</p>
  
  <pre><code>Instruction    M Cycles    T states   4 MHz E.t
  DEC r             1           4         1.00
  JP cc             3       10 (4,3,3)    2.50
  </code></pre>