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

direct programming Nios II

Altera_Forum
Honored Contributor II
1,269 Views

Can I use some low-level programming language (assembler) to programm NIOS II? 

I need to integrate NIOS II deeply in my system and I need only core functionality of NIOS II, so I want to have a full control over ALU of NIOS II. As I understand, NIOS II IDE dosn't allow me so much freedom.  

Please, Someone, suggest me some IDE wich will allow to use assembler commands, or macros. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/ohmy.gif
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
574 Views

You can use the Nios II IDE to write assembler. Just name your source file with a .s or .S extension, and it will be compiled as assembly.  

 

You can start your code from the standard full c entry point by providing the main function in assembler: 

 

               .section .text                .globl main main: 

 

This will give you the full device driver initialisation before your code starts. Presumably you want greater control than that, so you can use the alt_main entry point intstead: 

 

               .section .text                .globl alt_main alt_main: 

 

In this case the only code that will run before yours is the code defined in crt0.S. This deals with initialising the caches, the stack pointer, bss and the global pointer. 

 

If you want to take full control of the boot process, then copy the file crt0.S from the nios2 component into your system library project (not application project), and then modify this file as required. This copy will be used in preference to the one supplied by the nios2 component.
0 Kudos
Altera_Forum
Honored Contributor II
574 Views

Special thanks to monkeyboy ! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

Another question - about mixed programming (asm + c++).  

How can I call to functions in *.s files from C++ files in NIOS II lDE? 

 

Thanks.
0 Kudos
Altera_Forum
Honored Contributor II
574 Views

If all you want to do is run a few lines of assembler, then it would be easiest to use the compiler&#39;s asm statement. This is described in the gcc documentation that comes with the kit. You can also find examples of this within the HAL. 

 

If you really want to write the entire function in assembler, then you will need to ensure that the function adheres to the processors "application binary interface". This is described in the appendix of the Nios II Processor Reference Handbook, which is also supplied with the kit. 

 

To make the call from C++ rather than C you should declare the function as "extern C", e.g.: 

 

 

extern "c" { extern void my_asm_func (void); } 

 

That way you don&#39;t have to worry about the effects of the C++ mangler.
0 Kudos
Altera_Forum
Honored Contributor II
574 Views

Many Thanks. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif

0 Kudos
Reply