Forum Discussion
Altera_Forum
Honored Contributor
20 years agoAsm code and C imme
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, David7 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by david_cai@Dec 27 2005, 06:47 AM #define spi_0_base 0x00800980in 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
- Altera_Forum
Honored Contributor
Maybe try like this example :
This generates :#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");
For your problem, maybe this should work in the same waycustom 6,r0,r0,r0__asm__ volatile ("movhi r15,%hi" __str__(SPI_0_BASE)); - Altera_Forum
Honored Contributor
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 - Altera_Forum
Honored Contributor
Try with brackets around the value?
Stefaan__asm__ volatile ("movhi r15,%hi(" __str__(SPI_0_BASE) ")"); - Altera_Forum
Honored Contributor
check gcc document for the inline asm's args format, there are input regs, and output regs.
search the linux-2.6.x/include/asm-nios2nommu for some example. - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by hippo@Jan 6 2006, 08:37 PM check gcc document for the inline asm'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 ---
- Altera_Forum
Honored Contributor
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