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

error when using Conditional instruction - STM32f103

Hi every body !

I have a problem when using inline assembler instruct in C function.

T'm using Keil MDK V7.52 with STM32f103 family. I know that cortex M3 supports conditional instruction such as ANDEQ,ORREQ... But when i use it in "__asm{...}" block all conditional instructions generate error #2830 : cannot do desired conditional execution

I don't know how to solve it. Some one can help me ?

Thank you !

  • Maybe write an assembler function, instead of using assembler in a C function?

  • But i don't want to use BL instruction. It's cause performance is reduce. I only use some instruction such as add,sub.... and save N,OV,Z flag in APSW register. Of course i can use assembler function but i don't know how to make it as a inline function.

  • Are you sure it supports ANDEQ/ORREQ in the manner you're using them?

    "For the Cortex-M3, the conditional execution suffixes are usually used for branch instructions.
    However, other instructions can also be used with the conditional execution suffixes if they
    are inside an IF-THEN instruction block."

    Are you using ITTEE or ITE, etc? If you want commentary on the code that fails, you'll need to post the failing code.

  • thank you. It's my fault. I don't use IT instruction but compiler generated it so i don't get any problem. But __forinline does not work. complier generate BL.W UpdateMathFlag instruction so i add push,pop,bx to make it work

    here my code __forceinline __asm void UpdateMathFlag(uint8_t* status)
    { PUSH {r1} LDR r1,[r0]

    IT EQ ORREQ r1,#0x01 ; zero flag

    IT VS ORRVS r1,#0x02 ; Overflow Flag

    IT MI ORRMI r1,#0x04 ; negative flag

    STRB r1,[r0] POP {R1} BX LR
    }

    here my C version after add IT instruction.

    __inline void UpdateMathFlag2(uint8_t* status)
    { uint32_t temp; __asm { push {r1} LDRB temp,[status] BIC temp,#0x07

    IT EQ ORREQ temp,#1

    IT VS ORRVS temp,#2

    IT MI ORRMI temp,#4

    STRB temp,[status] }
    }

    Now no error occurs but Keil ARM C/C++ complier is stop working and say :internal fault in function which calls UpdateMathFlag2.

  • __forceinline __asm void UpdateMathFlag(uint8_t* status)
    { PUSH {r1} LDR r1,[r0]

    IT EQ ORREQ r1,#0x01 ; zero flag

    IT VS ORRVS r1,#0x02 ; Overflow Flag

    IT MI ORRMI r1,#0x04 ; negative flag

    STRB r1,[r0] POP {R1} BX LR
    }

    __inline void UpdateMathFlag2(uint8_t* status)
    { uint32_t temp;
    __asm { LDRB temp,[status] BIC temp,#0x07 IT EQ ORREQ temp,#1 IT VS ORRVS temp,#2 IT MI ORRMI temp,#4 STRB temp,[status] }
    }