Skip to main content
MHass.2
Associate II
August 3, 2021
Question

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

  • August 3, 2021
  • 1 reply
  • 980 views

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....

This topic has been closed for replies.

1 reply

TDK
August 3, 2021

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""."