Mixed C/assembly programs for i.MX RT1010

cancel
Showing results for 
Search instead for 
Did you mean: 

Mixed C/assembly programs for i.MX RT1010

Jump to solution
103 Views
Contributor III

Hello,

Code I am porting to the i.MX RT1010 includes an assembly function that is called from a C file. This assembly function finds the successor of an IEEE 754 double. I did this in TI’s Code Composer Studio like this:

C file (main.c):

//variables

double x;

double xplus;

//external functions

extern double successor(double);

//main

int main(void) {

xplus = successor(x);

}

Assembly file (successor.s):

              .global successor

 

successor

               VMOV R0,S0

               VMOV R1,S1

 

               ADDS R0,R0,#1

 

               BCC noOF                              ;carry cleared if no overflow

 

               ADD R1,#1

 

noOF      VMOV S1,R1

               VMOV S0,R0

 

               BX lr

 

When I try to compile this in MCUXpresso I receive the following errors:

bad instruction ‘carry cleared if no overflow’

bad instruction ‘noof VMOV S1,R1

bad instruction ‘successor’

instruction not supported in Thumb16 mode – ‘ADDS R0,R0,#1

Could someone please advise how to get this working in MCUXpresso?

Labels (1)
0 Kudos
1 Solution
3 Views
Contributor III

I haven't tested it yet, but from what I've read the Thumb-16 ADD instruction always sets the flags. However ADDS can be used by selecting the new unified syntax using the ".syntax unified" directive:

                                 .global successor
                                 .syntax unified

successor:
                                 VMOV R0,S0
                                 VMOV R1,S1

                                 ADDS R0,R0,#1

                                 BCC noOF                        /*carry cleared if no overflow*/

                                 ADD R1,#1

noOF:                       VMOV S1,R1
                                 VMOV S0,R0

                                 BX lr

View solution in original post

0 Kudos
2 Replies
3 Views
Contributor III

I have changed the successor.s file to the following and it is compiling without errors, but I had to replace the ADDS instruction with ADD, so I don't know if any carries will now be set in the APSR register. I'll test it and report back.

                   .global successor

successor:
                    VMOV R0,S0
                    VMOV R1,S1

                    ADD R0,R0,#1

                    BCC noOF                                     /*carry cleared if no overflow*/

                    ADD R1,#1

noOF:          VMOV S1,R1
                    VMOV S0,R0

                    BX lr

0 Kudos
4 Views
Contributor III

I haven't tested it yet, but from what I've read the Thumb-16 ADD instruction always sets the flags. However ADDS can be used by selecting the new unified syntax using the ".syntax unified" directive:

                                 .global successor
                                 .syntax unified

successor:
                                 VMOV R0,S0
                                 VMOV R1,S1

                                 ADDS R0,R0,#1

                                 BCC noOF                        /*carry cleared if no overflow*/

                                 ADD R1,#1

noOF:                       VMOV S1,R1
                                 VMOV S0,R0

                                 BX lr

View solution in original post

0 Kudos