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
  • thanks,

    1、I used ARMV8 that platforms is: ARM DS-5 Documentation > ARM Compiler 6 (64-bit platforms only) > armclang Reference Guide

         not armcc but armclang

    2、how to expand in C language?like this:

    void test_tt(void)

    {

          push_x1_x12;

    }

    3、If I want to define a macro with parameters, how to deal with it ?

    Replace:

     

    .macro cpus_tst_get_opcode, _reg0

    lsl \_reg0,\_reg0,#4

    lsr \_reg0,\_reg0,#24

    .endm

    albanrampon

Reply
  • thanks,

    1、I used ARMV8 that platforms is: ARM DS-5 Documentation > ARM Compiler 6 (64-bit platforms only) > armclang Reference Guide

         not armcc but armclang

    2、how to expand in C language?like this:

    void test_tt(void)

    {

          push_x1_x12;

    }

    3、If I want to define a macro with parameters, how to deal with it ?

    Replace:

     

    .macro cpus_tst_get_opcode, _reg0

    lsl \_reg0,\_reg0,#4

    lsr \_reg0,\_reg0,#24

    .endm

    albanrampon

Children
  • 2. Yes. The #define is identical to replacing the text.

    3. You use parameters like for a function:

    #define RADTODEG(x) ((x) * 57.29578)
    

    and in your code

    y = RADTODEG(25);
    

    will do:

    y = (25) * 57.29578;
    
  • sorry,

    //    define:

    //-------------------------------------

    #define  push_x1_x12     \

        __asm {                 \ 

         push x1,x2              \ 

         push x3,x4              \               

         push x5,x6              \ 

         push x7,x8              \ 

         push x9,x10             \ 

         push x11,x12            \ 

    }

    //     call

    //----------------------------------------

    void test_tt(void)

    {

    push_x1_x12;

    }

    ARM Compiler 6  Compilation error

    1.png

    javascript:liveAction('org.eclipse.help.ui', 'org.eclipse.help.ui.internal.ShowInTocAction', '2_4')

  • Oups, can you try the following?

    #DEFINE push_x1_x12 __asm("push x1,x2", "push x1,x2", "push x3,x4", "push x5,x6", "push x7,x8", "push x9,x10", "push x11,x12")



    6.4 Inline assembly language syntax with the __asm keyword in C and C++

  • The link just above also shows how to add parameters: you need to put them outside of the " " starting with #.

    There are several ways of declaring assembly instructions. One at a time, or a list. And for the list, the way I explained previously with curly brackets "{}" or like strings in round brackets "()".

    I am not sure why the curly brackets didn't work. It may depend on the compiler.

  • As described in the suggested by albanrampon to link section 6.4 Inline assembly language syntax with the __asm keyword in C and C++, the correct syntax is:

    //   define:
    //-------------------------------------
    #define  push_x1_x12  \
    __asm {                 \
        "push x1,x2   \n"   \
        "push x3,x4   \n"   \
        "push x5,x6   \n"   \
        "push x7,x8   \n"   \
        "push x9,x10  \n"   \
        "push x11,x12 \n"   \
    }
    
    //call
    //----------------------------------------
    void test_tt(void)
    {
    push_x1_x12;
    }
    

    See lacked the quotes involving the mnemonics and the line break.