0

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.

asked Sep 3, 2021 at 16:33
25
  • Use a debugger, step through assembly instructions. Or for starters at least look at the compiled assembly. Commented Sep 3, 2021 at 16:52
  • 1
    Then just compile it yourself and post the assembly here. armcc is proprietary and not commonly available. Commented Sep 3, 2021 at 17:28
  • 1
    If you don't have a debugger, that's your number 1 problem. You should fix that. (Even if just in a simulator, not on your real hardware). Many problems in asm become a lot more obvious when you single-step and watch register values change. (Although in this case, looking at the compiler's asm output may be sufficient.) Commented Sep 3, 2021 at 18:43
  • 1
    FWIW v5.01 is quite buggy. v5.06 is backwards compatible and is fixing many bugs. Also it is using same license, so better move to it.. Commented Sep 3, 2021 at 20:16
  • 1
    I'm not surprised volatile void jump() did nothing. If it's not already implicit for an asm {} block instead of GNU C style asm("template" :outputs : inputs : clobbers), you'd need to apply it to the asm keyword, not the function containing it. volatile void foo() doesn't mean "don't optimize this function". Commented Sep 3, 2021 at 20:28

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.