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

Replacing inline assembler code

Note: This was originally posted on 10th February 2011 at http://forums.arm.com

Hi,

My inline assembler looks like this

asm volatile (
    "MRC p15,0,$[value],c0,c0,1          \n\t"   
    : [value] "=r" (my_value)                                  
    );


Depends on the user input, I want to run different asm code. Is it possible to store the asm instruction in a C buffer than call it like

char *my_asm = "MRC p15,0,$[value],c0,c0,1          \n\t";
asm volatile (
    my_asm
    : [value] "=r" (my_value)                                  
    );


I tried this but no luck. Anyone have any idea on how I can achieve this? Thanks.

Parents
  • Note: This was originally posted on 10th February 2011 at http://forums.arm.com

    When you write:

    int foo(void)
    {
      int my_value;
      asm volatile (
        "MRC p15,0,$[value],c0,c0,1          \n\t"
        : [value] "=r" (my_value)
      );                                  
      return value;
    }


    The compiler produces something like:
    foo:
      MRC p15,0,r0,c0,c0,1
      BX lr

    and the assembler produces something like:

    0xEF000001
    0xE400000E


    In other words, without the compiler step, there is nothing to convert your string into the assembly and finally into machine code.
    If you wish to execute dynamically specified code, then either you need to provide all possible options, or write you own dynamic assembler.

    hth
    s.
    [/color]
Reply
  • Note: This was originally posted on 10th February 2011 at http://forums.arm.com

    When you write:

    int foo(void)
    {
      int my_value;
      asm volatile (
        "MRC p15,0,$[value],c0,c0,1          \n\t"
        : [value] "=r" (my_value)
      );                                  
      return value;
    }


    The compiler produces something like:
    foo:
      MRC p15,0,r0,c0,c0,1
      BX lr

    and the assembler produces something like:

    0xEF000001
    0xE400000E


    In other words, without the compiler step, there is nothing to convert your string into the assembly and finally into machine code.
    If you wish to execute dynamically specified code, then either you need to provide all possible options, or write you own dynamic assembler.

    hth
    s.
    [/color]
Children
No data