Search code examples
assemblyarmkeilthumb

IF ELSE Statements Operands


I have a very simple IF ELIF ELSE ENDIF statement to check if the value in r0 compared to other values. The code always throws the following errors when assembled:

main.s(25): error: A1198E: Unknown operand
main.s(27): error: A1198E: Unknown operand

I believe the issue has to do with perhaps =, <=,and >= not actually being operands that can function in IF statements, but based on the documentation on their website, = should work. The code is as follows:

       AREA    |.text|, CODE, READONLY, ALIGN=2
       THUMB
       EXPORT  Start
NEWVERSION dcw 2
Start
        mov r1, #21
        bl Price

loop   B    loop

Price 
            IF {[r1]! <= #13}
                mov r0, #6
            ELIF {[r1]! >= #65}
                mov r0, #7
            ELSE
                mov r0, #8
            ENDIF
            

       ALIGN      ; make sure the end of this section is aligned
       END        ; end of file

I'm aware that I have registers being compared to literals, but the code throws this error when [r0]! is replaced with some immediate value such as #12. There does not appear to be much information on how to use IF ELSE statements in Thumb, and I'm almost beginning to question if there is a behind the scenes reason why this may be the case, as most examples simply branch to subroutines of code or use the IT instruction.


Solution

  • According to the documentation:

    Use IF with ENDIF, and optionally with ELSE, for sequences of instructions or directives that are only to be assembled or acted on under a specified condition.

    These are not logical statements that control your program flow, but are directives to the assembler to include or exclude code depending on, for example, building for specific architectures.

    If you are familiar with C, these statements are like #ifdef preprocessor directives, not if() program flow statements.