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++

Asm code and C imme

Altera_Forum
Honored Contributor II
2,639 Views

Hi, 

 

In my project, I define a imme in *.c file: 

 

#define SPI_0_BASE 0x00800980 

 

In one of my asm routine, I wanna use this imme, how could I do? 

 

asm("movhi r15,%hi(SPI_0_BASE)"); 

 

I have tried the expression above, but compiling error occur and told me that SPI_0_BASE was undefined. 

 

Thanks any help, 

David
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
772 Views

 

--- Quote Start ---  

originally posted by david_cai@Dec 27 2005, 06:47 AM 

#define spi_0_base 0x00800980 

 

in one of my asm routine, i wanna use this imme, how could i do? 

 

asm("movhi r15,%hi(spi_0_base)"); 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11793) 

--- quote end ---  

 

--- Quote End ---  

 

 

It does not work because the symbol is inside " "...  

 

I do not know any escape unless you either substitute the symbol by hand or you rewrite the statement in C ... 

 

 

bye 

 

PJ
0 Kudos
Altera_Forum
Honored Contributor II
772 Views

Maybe try like this example : 

 

#define CUSTOM_INSTRUCTION_TEST 6 //expand the contents of val to "xxx"# define _str_(val)# val# define __str__(val) _str_(val) __asm__ volatile ("custom " __str__(CUSTOM_INSTRUCTION_TEST) ", r0, r0, r0"); 

 

This generates : 

custom 6,r0,r0,r0 

 

 

For your problem, maybe this should work in the same way 

 

__asm__ volatile ("movhi r15,%hi" __str__(SPI_0_BASE));
0 Kudos
Altera_Forum
Honored Contributor II
772 Views

Hi svhb, 

 

I have tried your method, but the following error occurred: 

 

{standard input}:241: Error: badly formed expression near %hi0x00800980 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif
0 Kudos
Altera_Forum
Honored Contributor II
772 Views

Try with brackets around the value? 

__asm__ volatile ("movhi r15,%hi(" __str__(SPI_0_BASE) ")"); 

 

 

 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
772 Views

check gcc document for the inline asm&#39;s args format, there are input regs, and output regs. 

search the linux-2.6.x/include/asm-nios2nommu for some example.
0 Kudos
Altera_Forum
Honored Contributor II
772 Views

 

--- Quote Start ---  

originally posted by hippo@Jan 6 2006, 08:37 PM 

check gcc document for the inline asm&#39;s args format, there are input regs, and output regs. 

search the linux-2.6.x/include/asm-nios2nommu/io.h for some example. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12010) 

--- quote end ---  

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
772 Views

An excellent description of gcc inline assembly can be found here: 

http://www.ibiblio.org/gferg/ldp/gcc-inlin...mbly-howto.html (http://www.ibiblio.org/gferg/ldp/gcc-inline-assembly-howto.html

 

also, check the nios2.h file. 

 

--wolf
0 Kudos
Reply