Forum Discussion
Altera_Forum
Honored Contributor
21 years agodirect programming Nios II
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.gif4 Replies
- Altera_Forum
Honored Contributor
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:
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 main 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..section .text .globl alt_main alt_main: - Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
If all you want to do is run a few lines of assembler, then it would be easiest to use the compiler'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.:
That way you don't have to worry about the effects of the C++ mangler.extern "c" { extern void my_asm_func (void); } - Altera_Forum
Honored Contributor
Many Thanks. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif