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

How to define a macro function

hi,

    I want to ask a question.

     How to define a macro function that can be called by C language in armasm?

     I know that in GNU can be used in the following way:

.macro push_x1_x12

push x1,x2

push x3,x4

push x5,x6

push x7,x8

push x9,x10

push x11,x12

.endm

ENTRY(test)

.......

push_x1_x12
......
ENDPROC(test)

  Now  in armasm, I used as follow :

MACRO

push_x1_x12

push x1,x2

push x3,x4

push x5,x6

push x7,x8

push x9,x10

push x11,x12

MEND

But how to expand the macro that can be called by C language??

Parents
  • albanrampon  @Peter Harris

    hi all,  

        I need to do some big test cases with macros.    

        read armclang's embedded assembly document.    and i can define macros in c ,and expand in c function .

        Now,I want to expand macros in other macros,the code as following:

    //define

    #define cpus_tst_code_lsl(_reg0,ret)  asm("adr  %[input_i],#4\n\t"      \

                "mov %[input_i],%[input_i]\n\t"    \

                "ldr %[input_i],[%[input_i]]\n\t"    \

                "lsl %[input_i],%[input_i],#36\n\t"  \

                "lsr %[input_i],%[input_i],#56\n\t"  \

                "cmp %[input_i],#0x80\n\t"    \

                "b.eq  lable1\n\t"      \

                "mov %[result],#0x1\n\t"      \

                "b lable2\n\t"        \

                "lable1:mov %[result],#0x0\n\t"    \

                "lable2:\n\t"        \

                : [result] "=r"  (ret)      \

                : [input_i] "r"  (_reg0)      \

              )

     

    //expand

     

    #define test_cpus_l1_code_base(ret)    asm("mov x5,#16\n\t"        \

                    "mov x6,x4\n\t"        \

                    "mov x8,#20\n\t"        \

                   "cpus_tst_code_lsl x5,%[result] \n\t"    \                                   

                    ........

                  : [result] "=r"  (ret)      \

                  :            \

                  )

    ARM Complier 6Complier  error:

        error: invalid instruction

    <inline asm>:4:2: note: instantiated into assembly here

            cpus_tst_code_lsl x5,x1

            ^

Reply
  • albanrampon  @Peter Harris

    hi all,  

        I need to do some big test cases with macros.    

        read armclang's embedded assembly document.    and i can define macros in c ,and expand in c function .

        Now,I want to expand macros in other macros,the code as following:

    //define

    #define cpus_tst_code_lsl(_reg0,ret)  asm("adr  %[input_i],#4\n\t"      \

                "mov %[input_i],%[input_i]\n\t"    \

                "ldr %[input_i],[%[input_i]]\n\t"    \

                "lsl %[input_i],%[input_i],#36\n\t"  \

                "lsr %[input_i],%[input_i],#56\n\t"  \

                "cmp %[input_i],#0x80\n\t"    \

                "b.eq  lable1\n\t"      \

                "mov %[result],#0x1\n\t"      \

                "b lable2\n\t"        \

                "lable1:mov %[result],#0x0\n\t"    \

                "lable2:\n\t"        \

                : [result] "=r"  (ret)      \

                : [input_i] "r"  (_reg0)      \

              )

     

    //expand

     

    #define test_cpus_l1_code_base(ret)    asm("mov x5,#16\n\t"        \

                    "mov x6,x4\n\t"        \

                    "mov x8,#20\n\t"        \

                   "cpus_tst_code_lsl x5,%[result] \n\t"    \                                   

                    ........

                  : [result] "=r"  (ret)      \

                  :            \

                  )

    ARM Complier 6Complier  error:

        error: invalid instruction

    <inline asm>:4:2: note: instantiated into assembly here

            cpus_tst_code_lsl x5,x1

            ^

Children