AnsweredAssumed Answered

asm branch out of range

Question asked by MICHAEL HUSLIG on Dec 13, 2015
Latest reply on Dec 17, 2015 by MICHAEL HUSLIG

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");


    __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");



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