Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Calculating the execution time of the program

Status
Not open for further replies.

Gastonjam

New Member
I'm trying to calculate the execution time of my program but I still can't manage how to do it .
This is my asmb code :
start:
MOV R1,A
loop1:
MOV R2, #250
loop2:
MOV R3, #250
loop3:
NOP
NOP
DJNZ R3,loop3
DJNZ R2,loop2
DJNZ R1,loop1
end


The program has an endless loop so how can this be calculated ? Even if it wasn't an endless loop how are the calculations done ?
 
Last edited:
That code needs a good tidying before anything else. Having labels at the begining and end of lines is plainly wrong.

Mike.
 
You simply consult the datasheet, which will tell you the execution time for the all the instructions (on a 16F PIC it's either one instruction cycle or two - others often vary much more), then do the maths. Bear in mind some instructions may vary, depending if the instruction passes or fails, such as DJNZ perhaps?.
 
You simply consult the datasheet, which will tell you the execution time for the all the instructions (on a 16F PIC it's either one instruction cycle or two - others often vary much more), then do the maths. Bear in mind some instructions may vary, depending if the instruction passes or fails, such as DJNZ perhaps?.
I did that when I started. Lot of work.

Eventually, when you run a simulation (if such a thing is possible in your IDE), you could also have kind of timer (or stopwatch) to tell how much time has elapsed for a certain part of your code.
 
I did that when I started. Lot of work.

So did I :D

When I started I also had to do hand assembly, bearing in mind it was back before PC's - then upgraded to a one pass assembler in EPROM, followed by a two pass assembler in EPROM.

However, doing the work helps you to understand the processor and system :D
 
Nigel, just to help you out, I ran it on my simulator.
Here are the results:

Including 2 states for the initial JMP past the standard 8051 interrupt vectors (which is good programming).
If you don't want this jump considered in the calculation, subtract two instruction cycles from everything that follows.

start:
2 instruction states to get to this point) MOV R1,A
loop1:
MOV R2, #250
loop2:
MOV R3, #250
loop3:
NOP
NOP
7 states to get to this point, and none of the above is in the loop, so is never counted again) DJNZ R3,loop3
1005 states to get to this point) DJNZ R2,loop2
250754 states to get this point) DJNZ R1,loop1
64192771 states to get to this point) end

Now, take all those states and multiple them by your instruction cycle time to get the actual run time (in minutes and seconds, etc..)
For example, at 1 microsecond instruction time, that would be: 64192771 * 0.000001 Sec = 64.192771 Seconds.

Hope this helps!
BTW, my first point.
I joined in the hopes of maybe getting an answer to an ugly problem I'm encountering with an 8051 derivative UART operating on the internal 8 MHz clock. I'll post that separately, shortly.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top