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

Conditional Check in Assemly File Like C Preprocessor

I want to set the stack size in assembly depending on if a definition exists, in the same in way as is done in the C preprocessor.

For example in C I would do this:

#ifdef SMALL_STACK
Stack EQU 0x00000800
#else
Stack EQU 0x00008000
#endif

I found this article in the Assembler User's Guide:

www.keil.com/.../armasm_dom1361290015842.htm

And tried this:

IF :DEF:SMALL_STACK
Stack EQU 0x00000800
ELSE
Stack EQU 0x00008000
ENDIF

but I get the error:

startup_MSP432P4.s(31): error: A1355U: A Label was found which was in no AREA

I can probably use the --cpreproc option as described here:

www.keil.com/.../armasm_dom1359731170696.htm

but this is more complication than I want to add to my project, especially for something so simple.

Is it possible to do what I want?

Thanks,
Samuel

  • Keil's own startup files are using conditional processing - have you looked at them?

    Next thing - you posted source code without following the posting instructions for how to post source code. So it isn't possible to see if you have done any indenting of your source lines.

    The assembler cares more about white space than the C compiler does.

  • Actually I didn't have any indentation, just as I showed it in my first post. I saw the conditional processing at the bottom of the startup file, I tried using it with the same indentation and without indentation and got the same error.

    For example with the same indentation:

        IF :DEF: SMALL_STACK
            Stack   EQU     0x00008000
        ELSE
            Stack   EQU     0x00080000
        ENDIF
    

    When I do this I get the following 3 errors:

    startup_MSP432P4.s(42): error: A1163E: Unknown opcode Stack , expecting opcode or Macro
    startup_MSP432P4.s(59): error: A1516E: Bad symbol 'Stack', not defined or external
    

    If I remove 4 spaces from each line, like this:

    IF :DEF: SMALL_STACK
        Stack   EQU     0x00008000
    ELSE
        Stack   EQU     0x00080000
    ENDIF
    

    I get the following error:

    startup_MSP432P4.s(39): error: A1355U: A Label was found which was in no AREA
    

    And if I remove all spaces, as I did in the first post:

    IF :DEF: SMALL_STACK
    Stack   EQU     0x00008000
    ELSE
    Stack   EQU     0x00080000
    ENDIF
    

    I get the following error:

    startup_MSP432P4.s(39): error: A1355U: A Label was found which was in no AREA
    

  • And didn't you see any pattern in this?

    If you had a label without indentation, you didn't get an error.
    If you had a label with indentation you did get an error.

    If you had your "IF" without indentation, you did get an error.
    If you had your "IF" with indentation, you did not get an error.

    So any reason why you didn't test the combination where you did not indent any label but did indent your "IF"?

    You did keep track of the line numbers for the error messages, and correlated with actual lines in your assembler file?

    And any reason why you didn't look through the assembler manual what rules there might be for white space?

    Or followed my suggestion and looked at Keil's sample startup files?

    As a developer, you need to analyze clues. And you need to consider what available sources you have of examples and documentation. Then you combine the available information and make own conclusions that you can then test. "Programming by forum requests" is a quite slow route - and not a route companies wants to pay salary for.

  • That got it. Thanks for your help and kind advice.