Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Z80assembly program Write a Z80assembly program Solution 1. Here is the

ID: 1829880 • Letter: W

Question

Write a Z80assembly program
Write a Z80assembly program

Explanation / Answer

1. Here is the sub-routine to make a delay loop of some time DLoop :      decbc                           ; Decrement Register BC (Initially holds some value)      jrnz,DLoop                 ; If BC != 0 , Jump to Delay Loop Using the data sheet given at www.z80.info/zip/z80cpu_um.pdf We find that DEC BC operation takes 6 Clock Cycles and    JR NZ,d takes 12 Clock Cyclesif Jump is made else 7 Clock Cycles. Hence if initial value of BC = Init then total delay caused by calling DelayLoop : T =(Init-1)*(6+12) + 6+7 = 18*Init - 5 Clock Cycles Since at 1 MHz clock speed, Duration of 1 Clock Cycle = 1 us To obtain a delay of 1 second we require            1us*(18*Init -5) = 1s           => Init = 1000005/18 =   = 55555.83 Since we use integer value of Init, Let us choose Init = 55555 Then actual delay caused   = (55555*18-5 )us =999985 us Also from data sheet we have LD BC,nn operation takes 10Clock Cycles = 10 us in our case and NOP takes 4 Clock Cycles = 4 us Thus the final Code for Delay Loop is    DelayLoop :          LD BC,D903H                 ; Load registers BC with D903H = 55555 Decimal . 10Clocks    DLoop :          DECBC                           ; Decrement BC ; 6 Clocks          JRNZ,DLoop                   ; Jump if not zero (12 Clocks) Else next line (7Clocks)         NOP                                 ; Do nothing .4 Clock Cycles             LDC,A                             ; Copy data of A in C (The address of output port A)          LDA,FFH                        ; Make all 1's in A          OUT(C),A                       ; Output content of A in Port C (Equivalent to Initial Addressdefined by A) Thus DelayLoop takes 10+99985 + 4 = 999999us = 1s After 1 s all 1's are send to port A. Hope this helps you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote