cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone, How can I get number of clock cycles to execute these assembly instructions ?

MHass.2
Associate III

I'm using stm32f429 Discovery board and I want to know number of cycles required to execute this part of assembly code .

ldr   r3, [pc, #64]  ; (0x8001228 <TIM1_UP_TIM10_IRQHandler+120>)

ldr   r3, [r3, #0]

ldr   r3, [r3, #36]  ; 0x24

ldr   r2, [pc, #64]  ; (0x800122c <TIM1_UP_TIM10_IRQHandler+124>)

ldr   r2, [r2, #0]

subs  r2, r3, r2

ldr   r3, [pc, #52]  ; (0x8001228 <TIM1_UP_TIM10_IRQHandler+120>)

ldr   r3, [r3, #0]

subs  r2, #25

str   r2, [r3, #36]  ; 0x24

this assembly code is equivalent to

htim1.Instance->CNT = htim1.Instance->CNT - q - 25 ;

where q is integer number calculated from another expression.

Thanks....

1 REPLY 1
TDK
Guru

You can see the number of cycles per instruction here:

https://developer.arm.com/documentation/ddi0439/b/CHDDIGAC

Note that this doesn't include delays due to accessing, such as flash wait states or bus contention issues.

You can use the DWT->CYCCNT counter to measure things, though you need to initialize it first.

  CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
  DWT->CYCCNT = 0;

If you feel a post has answered your question, please click "Accept as Solution".