ARM Inline assembly for C code not executing

262 Views Asked by At

I am trying to use inline assembly for an ARM C code. My 'main.c' code looks something like this:

...
void jump()
{
  __asm
  {
    B  0x15000
  }
}


INT32 main(void)
{
  ...
  Write val1 into register 1
  jump();
  Write val2 into register 2
  ...
}

When I run this code I expect that val1 to be written in register 1, and then jump to address 0x15000 happens and there is nothing written in register 2. But when I look at register 1 and register 2 both have been written with val1 and val2. So it seems the jump() does not take place. Am I missing something?

Update 1

As suggested in the comments, I created a minimum reproducible example which is:

void jump()
  {
    __asm
    {
      B  0x15000
    }
  }

int main(void)
{  
  int i, j, k;
  i = 1;
  jump();
  j = 2;
  k = i + j;
  return 128;
}

when I compile it with armcc --asm main.c I get this as main.s:

        ARM
        REQUIRE8
        PRESERVE8

        AREA ||.text||, CODE, READONLY, ALIGN=2

jump PROC
        BX       lr
        ENDP

main PROC
        MOV      r0,#0x80
        BX       lr
        ENDP


        AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALIGN=2

        DCD      0x00000000

so it looks like the jump() is optimized out? What is that and how can I prevent it?

Update 2

I even tried adding the volatile before the function name as:

 volatile void jump()
  {
    __asm
    {
      B  0x15000
    }
  }

but it didn't help and the jump() function is optimized out.

0

There are 0 best solutions below