CrazyEngineers
  • Calculation T-State in 8085

    vick5821

    Member

    Updated: Oct 26, 2024
    Views: 4.6K

    DELAY_1: MVI C,0AH
    LOOP: MVI D,64H
    LOOP_5: MVI E,0DEH
    LOOP_6: DCR E
    JNZ LOOP_6
    DCR D
    JNZ LOOP_5
    DCR C
    JNZ LOOP
    RET

    How do I calculate for the total delay of this code ?

    Anyone can help ?

    Thanks ><

    Pretty confused.

    Update (Answer):

    I can help you calculate the total delay of this assembly code for the Intel 8085 microprocessor.

    Here's a quick explanation on how to calculate the number of T-states, which are the internal clock pulses or ticks of the microprocessor:

    • MVI (Move Immediate) operation requires 7 T-states.

    • DCR (Decrement Register) operation requires 4 T-states.

    • JNZ (Jump if Not Zero) operation requires 7 T-states if the jump is taken, and 10 T-states if the jump is not taken.

    • RET (Return) operation requires 10 T-states.

    Given this information, we can calculate the total delay of your code as follows:

    1. MVI C,0AH --> 7 T-states

    2. LOOP: MVI D,64H --> 7 T-states

    3. LOOP_5: MVI E,0DEH --> 7 T-states

    4. LOOP_6: DCR E --> 4 T-states

    5. JNZ LOOP_6 --> If zero flag is not set (i.e., E != 0 after decrement), the jump is taken, costing 7 T-states. This loop (LOOP_6) will execute 0DEH times, each time taking 11 (4+7) T-states.

    6. DCR D --> 4 T-states

    7. JNZ LOOP_5 --> This will execute 64H times, each time taking (4+7 for DCR and JNZ operations + 0DEH * 11 for the LOOP_6) T-states.

    8. DCR C --> 4 T-states

    9. JNZ LOOP --> This will execute 0AH times, each time taking (4+7 for DCR and JNZ operations + 64H ((4+7) + 0DEH 11) for LOOP_5) T-states.

    10. RET --> 10 T-states

    So the total T-states will be:

    1 (MVI C,0AH) 7 T-states + 1 (MVI D,64H) 7 T-states + 1 (MVI E,0DEH) 7 T-states + 0DEH (LOOP_6 executions) 11 T-states + 64H (LOOP_5 executions) (4 (DCR D) + 7 (JNZ LOOP_5) + 0DEH 11 (LOOP_6)) T-states + 0AH (LOOP executions) (4 (DCR C) + 7 (JNZ LOOP) + 64H (4 (DCR D) + 7 (JNZ LOOP_5) + 0DEH 11 (LOOP_6))) T-states + 1 (RET) 10 T-states

    After simplifying the expression, you can calculate the total T-states for the delay code.

    The result will be a measure of time delay. To convert this into a time measure like milliseconds, you would need to know the clock frequency of your 8085 microprocessor. The relation is simple: if you have the microprocessor's clock frequency, you can calculate the time of one T-state (it's the inverse of the clock frequency), then multiply the number of T-states by the time of one T-state to get the total time delay.

    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Abhishek Rawal

    MemberMay 25, 2013

    You need value of clock cycle or clock period to calculate delay.
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    clock period is 0.5us.

    Thanks
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    I am just very confuse on how I can calculate this kind of question systematically ><
    Are you sure? This action cannot be undone.
    Cancel
  • Abhishek Rawal

    MemberMay 25, 2013

    Do you know how to calculate T-states ?
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    I know for a simple one. But still very confuse. Can you help me out ? Having an exam next week 😔

    Thnaks and appreciate 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Abhishek Rawal

    MemberMay 25, 2013

    This program is quite simple.
    You see first instruction ? That is counter 0A = 10 in decimal.
    Now step by step execute the instruction & note how many times a instruction executes the loop until the number turns to zero.
    Find total T-states & multiply it with clock period, You will get the answer.

    The calculation of T-states don't have any specific step. It depends upon the program & it's logic.
    In short I will say :
    Find total number of T-states& multiply it with clock period & get the execution time.
    In your case, The outer loop sets the multiplying count to the delay provided by the innermost loop. Though it seems tough it's quite easy.

    If you still have problem, I will explain you with a similar example but I won't answer this specific question. You have to obtain answer on your own.
    Sorry but that's where fun of logic lies, isn't it ? 😉
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    I think I need a similar example for this is it ok ?

    I really get my brain cell accident >< LOL
    Are you sure? This action cannot be undone.
    Cancel
  • Abhishek Rawal

    MemberMay 25, 2013

    Haha! Okay Here it is :

    Consider the program (which is very similar to yours) :
    MVI D,multiplier count (7T)
    L2: MVI C, DelayCount (7T)
    L1 : DCR C (4T)
    JNZ L1 (10T or 7T)
    DCR D (4T)
    JNZ L2 (7T or 10T)
    HLT

    T-states I have mentioned on right side of instruction with round brackets.
    Now calculations :
    T-states for innermost loop : 7 + (delay count - 1) x 14 + 11
    (*)T-states required for exe of program : (multiplier count - 1) x (T inner x 14) + 11

    Delay count : 0Ah (10) & multiplier count 5h

    Now you can easy calculate T inner : 7 + (10-1) x 14 + 11 = (Something something)
    Now put this value of T-states obtained in equation (*) & then multiply with clock period & you'll get the time required for executing the program 😀

    This is mere logic. Please note that there is no ideal method to calculate time delay for x-y-z program.
    The easiest thing to keep in mind is : Understand the program, calculate total T-states keeping no. of loops in mind & multiply it with clock period.

    I guess this helps 😀
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    Thank you so much for the guide ! I will try to solve mine and see how it goes !

    Appreciate your help 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Abhishek Rawal

    MemberMay 25, 2013

    Pleasure,Free feel to explore CrazyEngineers.
    And hey! spread the word 😀
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    Still very confuse on how I can categorised it ><
    sigh
    Are you sure? This action cannot be undone.
    Cancel
  • vick5821

    MemberMay 25, 2013

    (multiplier count - 1) x (T inner x 14) + 11,

    I do not understand this equation. (T inner x14) <--- very confuse for this .. Which part is it ?

    Thanks !
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register