This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Mixing C and Assembler

Hi

In order to make a stack checker in my Stellaris LM3S9D96 environment, I want to initialize the stack area with a specific pattern. The function used for that should take into account the actual position of the stack pointer, SP, and therefore I want to load a local variable with the SP. An often shown example of mixing C and Assembler looks the one below:

static int count_leading_zeros(uint32_t src)

{

    int ret;

    asm("CLZ ret, src");

    return ret;

 }

This indicates that local C variables can immediately be used within an __asm statement. However this does not work.

After a lot ot of searching around and a lot of unsuccessfull attempts my code look like this:

void HalInitStack(uint32_t ulPattern)

{

    extern uint32_t ulStack;

    __asm(" .bss _ulStack\n"

                " .global _ulStack\n"

                "  mrs  r0, MSP\n");

    while ((uint32_t*)ulStack >= (uint32_t*)__stack)    {

        *((uint32_t*)ulStack--) = ulPattern;

    }

 }

The .bss statement could not be translated.

I would very much appreciate if anybody would provide me a hint that could solve the mystery.

Thanks in advance.

Br Kenneth

  • It looks like the .bss assembly directive is not allowed inside a C function. There is a related thread here although the directive there is a different one. As mentioned in that thread a better method may be to implement the entire function in assembly code, and call the assembly function from the C code. Details on interfacing C and assembly can be found in the Compiler Users Guide.