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.

# char prefix needed for left/right shift constants?

I came across a strange behaviour of the assembler for # char. See the sample code lines given below with behaviour comments.

Is the char '#' must for all left/right shift constants? Then why is it behaving different in those two cmp statements? if I miss out that '#', for other instractions, it still assembles. But are these instrctions different? Can somebody explain?

Regards,

Sayee

 MOV ACC, #0x0C00 << #12 ; works

 MOV ACC,@_loc16 << #10 ; works

 ADD ACC,#23 << #6 ; works

 CMP PH, #MY_32BIT_MASK >> 16 ; works

 

 CMP PH, #MY_32BIT_MASK >> #16 ; does not work - assembler error

 

 

  • I filed SDSCM00039527 in the SDOWP system for this issue.  Feel free to track it with the SDOWP link in my sig below.

    Thanks and regards,

    -George

  • It is an oddity of the assembly language.   The instruction

     MOV ACC, #0xc000 << #12

    is of the form

     MOV ACC, #16BitSU { << shift2 }

    In this case, the two operands "#16BitSU" and "shift2" are distinct operands.  The language requires a '#' in front of "16BitSU" to distinguish this instruction form from the other other forms, but doesn't need that for "shift2," and in fact officially there isn't supposed to be a '#' in front of "shift2".  However, the assembler allows an optional '#' in front of "shift2", since the meaning is clear.

    On the other hand, the instruction

     CMP PH, #MY_32_BIT_MASK >> 16

    is of the form

     CMP loc, #16BitSigned

    In this case, the operand is actually "MY_32_BIT_MASK >> 16".  Think of it like this:

     CMP PH, #(MY_32_BIT_MASK >> 16)

    In this case, the assembler treats the entire expression "MY_32_BIT_MASK >> 16" as a math expression, not as part of the C2800 language.  In a math expression, the rules are different; in particular, '#' is not allowed at any point.

    It may be reasonable to allow '#' in front of constants in the math expression evaluator.