Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12748 Discussions

How to jump to labels which are defined in C code

Altera_Forum
Honored Contributor II
2,056 Views

Hi, 

 

In order to speed up system, I write a routine in ASM instructions. Then in asm code, I intend to jump to a label named LOOP which is defined in C code, but I failed. The following error occur: 

 

void Fast_Copy_In_ASM(alt_u32* pSource, alt_u32* pDest, alt_u32 length) 

LOOP: 

asm("ldwio r7,0(r4)"); 

asm("stwio r7,0(r5)"); 

asm("addi r5,r5,4");//increase read_data to point to next byte 

asm("addi r4,r4,4");//increase read_data to point to next byte 

asm("addi r6,r6,-4");//decrease read_length 

asm("bne r6,zero,LOOP ");//CWG2  

 

error:undefined reference to ‘LOOP’ 

 

(1)How to jump to labels which are defined in C code from asm instruction? 

 

(2)Also, pls kindly tell me does there exist any document related to C and ASM mixture coding? 

 

Thanks any help! 

David http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
901 Views

That is basically inline GCC assembly... that follow the rules of GCC ... you can find many information on the web just searching for "inline gcc assembler" :-) 

 

bye, 

 

Paolo
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

> error:undefined reference to ‘LOOP’ 

 

Put the label inline as well: <div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

asm volatile (                     

    "LOOP:  ldwio r7,0(r4)"  

    "        stwio r7,0(r5)"  

    "        addi r5,r5,4"       

    "        addi r4,r4,4"       

    "        addi r6,r6,-4"   

    "        bne r6,zero,LOOP " \  

);[/b] 

--- Quote End ---  

 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

smart idea http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

Thanks very much!
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

Hi Scott: 

I have tried your code, no compiling error occurred,but something was wrong. 

 

The following code work fine. 

asm("Fast_Copy_In_ASM_Loop: ldwio r7,0(r4)"); 

asm("stwio r7,0(r5)"); 

asm("addi r5,r5,4");//increase read_data to point to next byte 

asm("addi r4,r4,4");//increase read_data to point to next byte 

asm("addi r6,r6,-4");//decrease read_length 

asm("bne r6,zero,Fast_Copy_In_ASM_Loop");//CWG2 

But the code you showed me were all skipped when I step into it. 

asm volatile (  

"LOOP: ldwio r7,0(r4)"  

" stwio r7,0(r5)"  

" addi r5,r5,4"  

" addi r4,r4,4"  

" addi r6,r6,-4"  

" bne r6,zero,LOOP " \  

); 

 

WHY? 

 

best regards, 

David
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

> But the code you showed me were all skipped when I step into it. 

... 

> WHY? 

 

You might be stepping through each statement rather than each instruction. 

Each "asm" is treated as a statement.. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

Hi Scott: 

 

But I can&#39;t find the corresponding code in Disassembly window. 

So it might be optimized, am I right? 

But my optimization level is -O0. 

Can you help me to try the code? 

 

SOURCE CODE 

void Fast_Copy_In_ASM(alt_u32* pSource, alt_u32* pDest, alt_u32 length) 

asm volatile (  

"Fast_Copy_In_ASM_Loop1: ldwio r7,0(r4)"  

" stwio r7,0(r5)"  

" addi r5,r5,4"  

" addi r4,r4,4"  

" addi r6,r6,-4"  

" bne r6,zero,Fast_Copy_In_ASM_Loop1 " \  

);  

//asm("Fast_Copy_In_ASM_Loop: ldwio r7,0(r4)"); 

//asm("stwio r7,0(r5)"); 

//asm("addi r5,r5,4");//increase read_data to point to next byte 

//asm("addi r4,r4,4");//increase read_data to point to next byte 

//asm("addi r6,r6,-4");//decrease read_length 

//asm("bne r6,zero,Fast_Copy_In_ASM_Loop");//CWG2  

 

Disassembly code 

<span style="color:red"><span style="color:blue">void Fast_Copy_In_ASM(alt_u32* pSource, alt_u32* pDest, alt_u32 length) 

10053f4: defffc04 addi sp,sp,-16 

10053f8: df000315 stw fp,12(sp) 

10053fc: d839883a mov fp,sp 

1005400: e1000015 stw r4,0(fp) 

1005404: e1400115 stw r5,4(fp) 

1005408: e1800215 stw r6,8(fp) 

 

0100540c <Fast_Copy_In_ASM_Loop1>: 

asm volatile (  

100540c: 29c00037 ldwio r7,0(r5) 

"Fast_Copy_In_ASM_Loop1: ldwio r7,0(r4)"  

" stwio r7,0(r5)"  

" addi r5,r5,4"  

" addi r4,r4,4"  

" addi r6,r6,-4"  

" bne r6,zero,Fast_Copy_In_ASM_Loop1 " \  

);  

//asm("Fast_Copy_In_ASM_Loop: ldwio r7,0(r4)"); 

//asm("stwio r7,0(r5)"); 

//asm("addi r5,r5,4");//increase read_data to point to next byte 

//asm("addi r4,r4,4");//increase read_data to point to next byte 

//asm("addi r6,r6,-4");//decrease read_length 

//asm("bne r6,zero,Fast_Copy_In_ASM_Loop");//CWG2  

1005410: df000317 ldw fp,12(sp) 

1005414: dec00404 addi sp,sp,16 

1005418: f800283a ret</span></span> 

Thanks a lot! 

David
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

Duh ... sorry : 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

asm volatile (   

    "0:    ldwio r7,0(r4)  \n"  

    "          stwio r7,0(r5)  \n"  

    "          addi r5,r5,4  \n"   

    "          addi r4,r4,4  \n"   

    "          addi r6,r6,-4    \n"   

    "          bne r6,zero,0b \n"  

);[/b] 

--- Quote End ---  

 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

Hi, Scott: 

 

No sorry! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/happy.gif  

Thanks very much! 

 

Wish you a best christmas, 

David
0 Kudos
Altera_Forum
Honored Contributor II
901 Views

Hi, Scott: 

 

No sorry! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/happy.gif  

Thanks very much! 

 

Wish you a best christmas, 

David
0 Kudos
Reply