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

NIOS II Assembler example?

Altera_Forum
Honored Contributor II
2,003 Views

I am kind of stuck with my board working quite fine under debugger and not working full speed, standalone and I am searching for other options to troubleshoot... 

 

One idea I have is to write a little memory test code in NIOS II assembler executing from an internal sram or flash and testing my external SRAM which is probably acting up. 

 

I cannot find any example programs written in assembly language for NIOS II. I looked into NIOS II Software Developer's Handbook and "assembler" is not even mentioned in the Index on the back of this book... What book should I look for on Altera website? 

 

Anybody has any experience in writting in assembler for NIOS II or we just do everything in C/C++ and assembler language is long forgotten? http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif It would be really nice if there was some example project file with small code main.s or other assembler module. 

 

Any ideas appreciated.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
1,038 Views

If you add the switch "-save-temps" to your GCC flags, the compiler will keep the intermediate ".s" (assembler source) file for each C or C++ module - instant assembler examples!

0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

Talking about assembler, has anyone been able to step through assembler code in the NiosII IDE? I can step through C code, and my assembler compiles and runs, but I cannot step through it and break points are ignored.

0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

Seems like Frankie is having the same problem. If an answer is posted, please post to both threads. 

http://www.niosforum.com/forum/index.php?a...t=st&f=17&t=174 (http://www.niosforum.com/forum/index.php?act=st&f=17&t=174)
0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

 

--- Quote Start ---  

originally posted by steve360@Jul 20 2004, 06:09 AM 

if you add the switch "-save-temps" to your gcc flags, the compiler will keep the intermediate ".s" (assembler source) file for each c or c++ module - instant assembler examples! 

--- Quote End ---  

 

Thanks - this is a good idea but this is not really what I was looking for.  

An option to "compile via assembler" in the tools by bigger boys (Microsoft, Borland) creates listings including assembler lines following directly lines in C-code they replace. Also, they use C-level function/variable names in assembler to make it easier to understand what compiler have done with the C-code. 

 

Also, I have not only problems with creating a assembly file but also having problems compiling *.s files I found on my harddrive in nios2 folders. The project settings or make file is just not ready to compile assembler files. I got build errors like "Error *** No rule to make target `all&#39;. Hello_Assembler" and "Error *** No rule to make target `clean&#39;. Hello_Assembler " indicating I have something really wrong with my project files/make files.
0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

 

--- Quote Start ---  

originally posted by mumford@Jul 27 2004, 07:25 PM 

talking about assembler, has anyone been able to step through assembler code in the niosii ide?  i can step through c code, and my assembler compiles and runs, but i cannot step through it and break points are ignored. 

--- Quote End ---  

 

Looks like you moved much more far away from the starting point than I managed to move... I am not able even to compile/link my assembler code... Would you be so kind and send me you software project containing assembly modules as a reference? I know it is not perfect because you have some debugger problems, but at least you can get the target executable - I am not so lucky :-) 

 

Thanks!
0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

Pszemol, 

 

If I were you, I would use some of the suggestions that have already been presented.... 

 

1. Try the --save-temps and/or -S option to gcc. 

- No, this won&#39;t get you a whole lot further, but it will show you the details of assembly code for Nios II. 

2. Try right-clicking on the project and scrolling to "Refresh" prior to "Building" your .s files. 

- This refreshes your project&#39;s contents and, in theory, should make it "visible" to the build process. 

3. Be aware that -O2 or -O3 optimized code does nearly as good a job of optimization as hand assembly, unless, of course, you&#39;re an assembly genious http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

I have used these sorts of methods to compile assembly using the IDE. 

 

Cheers and Good luck! 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
1,038 Views

1. I started with assembly language by first creating a simple C Project, 

e.g. "Hello Led"  

2. I set compiler flag --save-temps  

3. I added a new C file "sample1.c" to the project,e.g with following code 

and called the function from the main loop 

... 

void sample1(void) { 

int i; 

i = 0; 

while (i<200000) { 

i++; 

4. you can now check under Debug/sample1.s the generated assemply language 

 

5. I then added a file "test.S" (remark upper&#39;S&#39;) to the project. 

 

.file "test.S" 

 

.section .text 

.align 3 

.global samplefunction 

.type samplefunction,@function 

 

samplefunction: 

addi sp, sp, -48 

 

stw r16, 36(sp) 

stw r17, 32(sp) 

stw r18, 28(sp) 

stw r19, 24(sp) 

stw r20, 20(sp) 

stw r21, 16(sp) 

stw r22, 12(sp) 

stw r23, 8(sp) 

stw fp, 4(sp) 

stw ra, 0(sp)  

 

 

# here we start 

.. some usefull code 

 

ldw r16, 36(sp) 

ldw r17, 32(sp) 

ldw r18, 28(sp) 

ldw r19, 24(sp) 

ldw r20, 20(sp) 

ldw r21, 16(sp) 

ldw r22, 12(sp) 

ldw r23, 8(sp) 

ldw fp, 4(sp) 

ldw ea, 0(sp) 

 

addi sp, sp, 48 

 

ret 

 

6. I added a call to samplefunction() in the main loop 

The file should compile normal, it should generate a file DEBUG/test.s and 

DEBUG/obj/test.o, the last is important for debugging 

 

 

 

assembler debugging: 

 

the problem seams to be that the assembly routines are not shown in the 

Outline Window. 

 

the only trick I found, is the following 

 

1. switch to C/C++ Development Perspective 

2. in C/C++ Projects go to  

yourProject/Debug/obj/yourAssemblerFile.o 

 

You should see there your assembly subroutines with a green point in front 

Right Click the function you want to debug, and click 

"Add/Remove Breakpoint"  

3. Switch back to Debug Perspective, and check under Breakpoints, if your  

breakpoint was set. 

start your program, it should now stop at the beginning of your assembler 

function, showing the assembly instructions. 

 

Remark: Perhaps you must already check under  

"Windows->Preferences->C/C++->Debug"  

"Automatically switch to dissassembly mode" 

 

hope this helps
0 Kudos
Reply