Calculation T-State in 8085
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:
MVI C,0AH --> 7 T-states
LOOP: MVI D,64H --> 7 T-states
LOOP_5: MVI E,0DEH --> 7 T-states
LOOP_6: DCR E --> 4 T-states
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.
DCR D --> 4 T-states
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.
DCR C --> 4 T-states
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.
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.
Replies
-
Abhishek RawalYou need value of clock cycle or clock period to calculate delay.
-
vick5821clock period is 0.5us.
Thanks -
vick5821I am just very confuse on how I can calculate this kind of question systematically ><
-
Abhishek RawalDo you know how to calculate T-states ?
-
vick5821I know for a simple one. But still very confuse. Can you help me out ? Having an exam next week ๐
Thnaks and appreciate ๐ -
Abhishek RawalThis 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 ? ๐ -
vick5821I think I need a similar example for this is it ok ?
I really get my brain cell accident >< LOL -
Abhishek RawalHaha! 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 ๐ -
vick5821Thank you so much for the guide ! I will try to solve mine and see how it goes !
Appreciate your help ๐ -
Abhishek RawalPleasure,Free feel to explore CrazyEngineers.
And hey! spread the word ๐ -
vick5821Still very confuse on how I can categorised it ><
sigh -
vick5821(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 !
You are reading an archived discussion.