Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Asm 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,

David

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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));
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Try with brackets around the value?

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

    Stefaan
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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