asm branch out of range

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

asm branch out of range

Jump to solution
1,379 Views
michaelhuslig
Contributor IV

I am trying to port an "asm void function(){}" in a C file from CW to KSDK.  The latter half of the converted function is below.  However I am getting a branch out of range error for the second instruction, the "cbz r0,noshift".  This is the only forward reference for any branch in the routine;  the reverse references, such as the "bne shiftloop" don't have a problem.  Actually, I would prefer to move the routine to a .S file and make it a pure assembly language routine and avoid the extra overhead at the beginning and end of the C routine, but then I have other problems with the assembler not recognizing several of the asm instructions that the compiler recognizes, such as push/pop {r0-r11,lr}.

 

 

__asm("str   r1,[r2,#4]");

 

    __asm("cbz   r0,noshift");
    __asm("ldr   r2,[sp,#2*4]");   
    __asm("ldr   r0,[sp,#0]");  
    __asm("asr   r2,r2,#2");

shiftloop:

    __asm("ldr   r3,[r0,#8]");
    __asm("ldr   r4,[r0,#12]");
    __asm("str   r3,[r0,#0]");
    __asm("str   r4,[r0,#4]");
    __asm("add   r0,#8");   
    __asm("sub   r2,#1");   
    __asm("bne   shiftloop");

   

noshift:

    __asm("pop   {r0-r11,lr}");
    __asm("bx   lr");

}

Labels (1)
0 Kudos
1 Solution
1,118 Views
michaelhuslig
Contributor IV

I don't know about the forward reference, but I did find out why I was getting errors on the push/pop instructions.  I needed to add ".syntax unified" to the .S file.

View solution in original post

0 Kudos
1 Reply
1,119 Views
michaelhuslig
Contributor IV

I don't know about the forward reference, but I did find out why I was getting errors on the push/pop instructions.  I needed to add ".syntax unified" to the .S file.

0 Kudos