Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

assembly 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

hanshaohua

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I'm using Monitor program and C language setting. I have a .s file which itself includes the "macros.s" . But I get the same error : Can't open macros.s for reading: No such file or directory

    1. I tried using .S file instead of .s

    2. I used Eclipse as default working directory

    3. I have main function in C and tried _main or _start or _alt_main in my assembly file

    Any suggestion?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Failure to open macros.s is a problem with the list of directories passed to gcc (acting as cpp) as -I dir_name.

    I've no idea what is in it - but I don't think your little file relies on any of it.

    You'll cut out a lot of the library code that gets added by the build it you call your function alt_main (not main).

    Also, as is mentioned earlier in this thread, if you aren't using any of the Altera BSP or libc functions, you don't need any of their setup code. The only initialisation required before jumping into C code is to set %sp and %gp. For your two instruction loop even those aren't needed.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    [SOLVED] here's how I fixed the problem.

    I copied the compilation command from monitor program in info & Errors window and pasted in nios2 command shell and it compiled the program with no error. Now my program works but 1 problem still remains; In the compilation command there's a option -mno-cache-volatile. nios2 Command shell complains that this option is not known so I have to remove it. here's the full command:

    nios2-elf-gcc -g -O1 -ffunction-sections -fverbose-asm -fno-inline -mno-cache-volatile -mno-hw-mulx -mhw-mul -mhw-div -Ic:/altera/91sp2/nios2eds/components/altera_nios2/HAL/inc -DSYSTEM_BUS_WIDTH=32 -DALT_SINGLE_THREADED -D_JTAG_UART_BASE=0x10001000 -Wl,--defsym -Wl,nasys_stack_top=0x800000 -Wl,--defsym -Wl,nasys_program_mem=0x1000 -Wl,--defsym -Wl,nasys_data_mem=0x10000 -Wl,--section-start -Wl,.exceptions=0x20 -Wl,--section-start -Wl,.reset=0x0 -Wl,--script=c:/altera/91sp2/quartus/../University_Program/Monitor_Program/build/nios_cpp_build.ld -o "C:/Documents and Settings/user/Desktop/test1/main.elf" "C:/Documents and Settings/user/Desktop/test1/main.c" "C:/Documents and Settings/user/Desktop/test1/playback.s" c:/altera/91sp2/quartus/../University_Program/Monitor_Program/lib/jtag_uart.c

    Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The -mno-cache-volatile causes gcc (3.4.6) to use the 'io' forms of instructions for volatile memory accesses (thus bypassing the data cache).

    This is likely to cause more grief than it fixes.

    Not sure why it would fail the compile.

    In any case it shouldn't be the default for the IDE, so you must have ticked something to enable it.