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.