AnsweredAssumed Answered

Stack overflow or some other weird thing after call of asm routine

Question asked by Sven Savic on Aug 14, 2016
Latest reply on Aug 30, 2016 by Tomas Krysl

I am using LPCXpresso v8.2.0 [Build 647] on Mac OS. My code is written in C++ and I am using asm routine for precise us delay. Processor is LPC54102.

For some reason after return from ASM call, my this pointer gets garbled, local member values are overwritten with some random values.

I am not sure if the problem is with ASM or some setting in IDE to enlarge stack size or ?

This code works fine on Cortex M3/M0 within the Keil IDE.  Havent tried it with M4 in Keil.

Stepping through the routine doesnt reveal anything until the "BX lr" code returns to C++ part of code, then my values are already overwritten.


void _delay_us (int a_us)


  asm(" CBZ R0, end");


  asm(" MOV R2, R0");


  asm(" MOV R1, #15");


  asm(" NOP");

  asm(" NOP");

  asm(" NOP");

  asm(" NOP");

  asm(" SUB R1, R1, #1");

  asm(" CMP R1, #0");

  asm(" BNE loop");

  asm(" SUB R2, R2, #1");

  asm(" CMP R2, #0");

  asm(" BNE loop2");


  asm(" BX lr");



And any kind of delay will cause overwrite ...

For example: