This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to propagate a value from C to a SPACE directive with armasm

Hi all,

I would like to ask help to some expert in armasm.

In my startup.s file I have the following code which reserves 0x400 bytes of RAM to the stack.

; this is the original startup.s file
Stack_Size      EQU     0x00000400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp

Well, I would like to be able to initialise Stack_Size with a value which I have in a cfg.h file or with a const value which I have in a cfg.c file

// this is cfg.h file
#define STACK_SIZE  0x00000400
// this is cfg.c file
#include "cfg.h"
extern const int Stack_Size = STACK_SIZE;

The problem is that I dont know how to export the variable from C and import it into assembly.

I tried to use IMPORT, as in the following, but it does not work.

; this is the modified startup.s

                IMPORT Stack_Size
;Stack_Size      EQU     0x00000400
;               EXPORT  Stack_Size

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp

Any suggestion?

Thanks in advance, Marco.

Parents Reply Children
  • Hi,

    I already do that. However, it is not just enough to use an extern variable called Stack_Size, but you need to use some more code:

    // this is startup.s
    Stack_Size      EQU     0x00000400
                   EXPORT  Stack_Size
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    Stack_Mem       SPACE   Stack_Size
    __initial_sp
    
    // this is myfile.c
    __asm int getstacksize (void) {
            IMPORT  Stack_Size
            LDR     R0,=Stack_Size
            BX      LR
    }
    

    However, it is not what I want to do.

    My aim is to hide the startup.s and use just .h and .c files for configuration.

    Thank anyway, marco.