Hi,
can you please tell me how to calculate execution time from the listing file shown below

1                     ; C Compiler for M68HC08 (COSMIC Software)
   2                     ; Generator V4.5.10.1 - 14 Jun 2007
   3                     ; Optimizer V4.5.4.2 - 17 Jul 2007
   5                        xref   _printf
  32                     ; 1 void main(void)
  32                     ; 2 {
  33                        switch   .text
  34  0000               _main:
  38                     ; 3 printf(" hello world "); 
  40  0000 a600             lda   #low(L71)
  41  0002 ae00             ldx   #high(L71)
  43                     ; 4 }
  46  0004 cc0000           jmp   _printf
  58                        xdef   _main
  59                     .const:   section   .text
  60  0000               L71:
  61  0000 2068656c6c6f     dc.b   " hello world ",0
  62                        end

in the above listing file:
instruction lda takes 2 cycles
instruction ldx takes 3 cycles
instruction jmp takes 3 cycles

can you please give me some idea to calculate execution time.
Thanks....

Huh? Just sum up the clock cycles you posted, but that does not include the time printf() function takes.

If you want a better way to profile your program, use clock() function which return time_t object

int main()
{
    clock_t t1, t2;
    t1 = clock();
    // put your code here

    t2 = clock();
    printf("Diff = %d\n", t2 - t1);
}

Depending on your program you might see that t1 and t2 are the same time, meaning your program ran too quickly to be measurable. Many programmers will repeat the code several times (or millions of times) in between t1 and t2 in order to get measurable time.

Just sum up the clock cycles

given if i sum up the clock cycles, how can i know the execution time by using the cycles?
i knew one method which is,
execution time = CPU clock cycles * clock cycle time

CPU clock cycles = no of instructions * cycles/instruction

but i am not sure, if this method will give me execution time.

please give me some ideas.
thanks...

>>CPU clock cycles = no of instructions * cycles/instruction
That won't work even if you did manage to get all the cycles. It's not the "number of instructions" because each instruction has a different number of clock cycles. You would have to add up all the instructions in the program, including function calls such as printf(). And I don't think that would be possible unless you have the source code for those functions. And then it would depend on what compiler you used because each compiler might compile the same source code down to different machine-language.

>>but i am not sure, if this method will give me execution time.
Probably not. See my previous post for use of clock() function to measure execution time which will include all function calls.

so what should i do now?
i sum up the instructions and use clock() function to get the time???

in the previous reply you told to insert the code in between the clock() function. what code should i write their?

Thanks for the reply...i am a bit confused not able to think correctly..

please check this listing file mentioned below, it does have any funtions.
what should i do now to calculate execution time??
my first step is to sum up all the clock cycles from instructions.
what is my next step??how will i know the execution time from clock cycles?? i am using HC08 compiler it has 8MHz CPUstandard bus frequency

1                     ; C Compiler for M68HC08 (COSMIC Software)
   2                     ; Generator V4.5.10.1 - 14 Jun 2007
   3                     ; Optimizer V4.5.4.2 - 17 Jul 2007
  39                     ; 4 void main(void)
  39                     ; 5 {
  40                     	switch	.text
  41  0000               _main:
  43  0000 a7fe          	ais	#-2
  44       00000002      OFST:	set	2
  47                     ; 7 if ( X > 5 )
  49  0002 95            	tsx	
  50  0003 e601          	lda	OFST-1,x
  51  0005 a006          	sub	#6
  52  0007 f6            	lda	OFST-2,x
  53  0008 a200          	sbc	#0
  54  000a 9107          	blt	L32
  55                     ; 8   X= X + 1;
  57  000c 6c01          	inc	OFST-1,x
  58  000e 2611          	bne	L52
  59  0010 7c            	inc	OFST-2,x
  61  0011 200e          	bra	L52
  62  0013               L32:
  63                     ; 10    X= X * 3;
  65  0013 8c            	clrh	
  66  0014 ae03          	ldx	#3
  67  0016 9ee601        	lda	OFST-1,sp
  68  0019 b700          	sta	c_reg
  69  001b 9ee602        	lda	OFST+0,sp
  70  001e cd0000        	jsr	c_imul
  72  0021               L52:
  73                     ; 11 }
  76  0021 a702          	ais	#2
  77  0023 81            	rts	
  89                     	xdef	_main
  90                     	xref.b	c_reg
  91                     	xref	c_imul
  92                     	end

so what should i do now?
i sum up the instructions and use clock() function to get the time???

No -- just forget the idea of summing up the clock cycles.

in the previous reply you told to insert the code in between the clock() function. what code should i write their?

whatever code you plan to measure!

please check this listing file mentioned below, it does have any funtions.
what should i do now to calculate execution time??
my first step is to sum up all the clock cycles from instructions.
what is my next step??how will i know the execution time from clock cycles?? i am using HC08 compiler it has 8MHz CPUstandard bus frequency

The next step would be to look up the cpu cycles in an assembly language book, or probably on-line. But I honestly don't know why you would want to do this, unless of course it is your class assignment. Nobody in his right mind would do it for rea-world programs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.