Forum Discussion
Altera_Forum
Honored Contributor
16 years agoassembly language in the nios ii ide
Hi
does the nios ii ide support assemble language? why does my assemble codes occur errors? my setup project proceed as follows: 1 Start the Nios II IDE. (Start->All Programs->Altera->NiosII EDS 9-> NiosII 9 IDE 2 Creat a new project. File->New->Project Nios II C/C++ Application 3 Select blankproject from templates 4 Set the project name 5 Select the target hardware( sopc builder system has been setup) 6 Click Next 7 Click New system libary 8 Click Finish 9 Add a file with name basics.s (File->New->Other This opens a popup where you can pick File from under the General Category, after selecting File, you need to specify the name at the bottom (use basics.s) 10 enter the code: .include"nios_macros.s" .text .equ TEST_NUM,0x90abcdef .global _start _start: movia r7,TEST_NUM mov r4,r7 STRING_COUNTER: mov r2,r0 STRING_COUNTER_LOOP: beq r4,r0,END_STRING_COUNTER srli r5,r4,1 and r4,r4,r5 addi r2,r2,1 br STRING_COUNTER_LOOP END_STRING_COUNTER: mov r16,r2 END: br END .end 11 Use Debug As -> Nios II Instruction Set Simulator which will build the project (assemble the file) and start the debugger. then errors occur errors: /cygdrive/d/altera/90/nios2eds/components/altera_hal/HAL/src/alt_main.c undefined reference to `main' /cygdrive/d/altera/90/quartus/FPGA_code/computer_organization/lab_ex1/part1_1/software/asm_first_syslib/Debug/crt0.o(.text+0x0):/cygdrive/d/altera/90/ip/altera/nios2_ip/altera_nios2/HAL/src/crt0.S first defined here /cygdrive/d/altera/90/quartus/FPGA_code/computer_organization/lab_ex1/part1_1/software/asm_first_syslib/Debug/libasm_first_syslib.a(alt_main.o) In function `alt_main': Can't open nios_macros.s for reading: No such file or directory obj/part2.o In function `_start': Warning: end of file not at end of a line; newline inserted ps: 1 i'm sure the codes are right(de2-70 labs exercises/computer organization/lab1) 2 the operator proceed is from duke.edu by google forgive my ugly English,:D. Best regards hanshaohua14 Replies
- Altera_Forum
Honored Contributor
Use:
.global _alt_main _alt_main: instead of: .global _start _start: you need the C runtime startup to initialize the NIOS II system and it jumps to _alt_main. Bill - Altera_Forum
Honored Contributor
--- Quote Start --- you need the C runtime startup to initialize the NIOS II system and it jumps to _alt_main. --- Quote End --- Strictly speaking, this isn't true. If you drop the Altera provided syslib/bsp entirely, you can avoid all the default C runtime and initialization stuff. If you include the syslib/bsp as it appears the OP has done, then you do need to define either _alt_main or _main as you have suggested. - Altera_Forum
Honored Contributor
Thank you,Bill.
I'm new to nios ii system. By now, i don't know the assembly code or my wrong operating proceed cause wrong. But from the nios ide errors tips, nios ii can't recognize the assembly code . - Altera_Forum
Honored Contributor
--- Quote Start --- Strictly speaking, this isn't true. If you drop the Altera provided syslib/bsp entirely, you can avoid all the default C runtime and initialization stuff. If you include the syslib/bsp as it appears the OP has done, then you do need to define either _alt_main or _main as you have suggested. --- Quote End --- Hi,Kevin. It's kind of you . I have modifed the assembly code using .global _alt_main _alt_main: instead of .global _start _start: But it does not work, yet occur errors as mentioned by me. - Altera_Forum
Honored Contributor
Have you tried _main instead of _alt_main?
- Altera_Forum
Honored Contributor
--- Quote Start --- Have you tried _main instead of _alt_main? --- Quote End --- yes,have the same errors. If there is something wrong with the code, i can continue to work on labs exercises. But,if nios ii does not support assembly code , i have no idea how to go on. May be i can try nios ii command shell( i'm familiar with linux and know of many commands). :) Thanks all the same. hanshaohua - Altera_Forum
Honored Contributor
Sorry to ask this but why use assembly language? Why not use C? The NIOS II GCC compiler generates code as good as and probably better than any assembly code I've written.
Bill - Altera_Forum
Honored Contributor
--- Quote Start --- Sorry to ask this but why use assembly language? Why not use C? The NIOS II GCC compiler generates code as good as and probably better than any assembly code I've written. Bill --- Quote End --- Hi,bill. yes,i am more familiar with C more than assembly language. Acutually speaking, i am doing labs exercises using DE2 . And DE2 provides assembly codes exercises. Most of all, i am new to niso ii system. hanshaohua - Altera_Forum
Honored Contributor
Finally, the problem is solved.
1 assembly file is xx.S,not xx.s 2 You must have a function or label called main. If main is written in assembly-language, the label main must be declared global with the .global directive. 3 Project default in Eclipse woring dir would be best. Thank you ,Bill,Kevin. - Altera_Forum
Honored Contributor
Hi!
I still have the error, my asm sour file is main.S, the code from a NIOSII tutorial: .include "nios_macros.s".equ switches, 0x41020
.equ leds, 0x41030
.global main
main:
movia r2, switches
movia r3, leds
loop:
ldbio r4, 0(r2)
stbio r4, 0(r3)
br loop but: alt_main.c:154: undefined reference to `main' :(