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

Combining Assembly and C

Altera_Forum
Honored Contributor II
2,405 Views

Hi,  

 

I am very new to Hardware Programming, and I am using the NIOS II processor to identify the frequency of a sound that is input into the DE1 Board. My question is, is it possible to combine NIOS II Assembly and C in one project using the NIOS II 10.0 IDE Software. More specifically I would like to do the FFT in C and store the result in memory. Then using Assembly I would like to retrieve the value from memory and output that result to the HEX display. If it is possible, is there any documentation that explains how to do that?  

 

Thanks
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
1,247 Views

Since the Nios C compiler is based off of gcc, it should support inline assembly code. 

 

See here: http://stackoverflow.com/questions/61341/is-there-a-way-to-insert-assembly-code-into-c 

 

As far as accessing the same memory locations, a google search should point you in the right place. 

 

-Jay
0 Kudos
Altera_Forum
Honored Contributor II
1,247 Views

If you worry about performance, use reduced HAL driver, which is faster in footprint. The C compiler is very optimize to handle what you are trying to accomplish.

0 Kudos
Altera_Forum
Honored Contributor II
1,247 Views

Thanks for the responses,  

I am not really going for performance I need to include some Assembly in my C code for a university project, and it only needs to be some simple instructions, to read a value from memory and output it to the HEX displays on the board.
0 Kudos
Altera_Forum
Honored Contributor II
1,247 Views

I am sorry. My assembly experience on Nios II is very limited. If you need to do this in C, then look at IORD and IOWR.

0 Kudos
Altera_Forum
Honored Contributor II
1,247 Views

Usually such operations can be done in C. 

For actual assembler either write an assembler source file containing C callable code (I think the Altera makefile will put a .S file through cpp and then gas), or use the gcc 'asm' statement to include the required instructions - these will tie C variables to registers as required. 

There should be some exampler lurking in the .h files or more generally on the web. 

NB: if you access any memory locations that C variables also access, then add a "memory" qualifier to the asm statement - otherwise gcc might optimise out the C code.
0 Kudos
Reply