Forum Discussion

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

assembly prog

Hi

Has anyone tried to write assembly language programs for nios II processor? If so plz tell me how to start the program i.e., i mean to say are any initial statements required like main() in c-lang. I wrote a sample program as follows but the error is that " %g0 not a valid register" , "%g1 not a valid register".

.text

MOVI %g0,9

MOV %g1,%g0

NOP

So someone please tell me how to overcome the problem

4 Replies

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

    Hi rakesh,

    You can find example assemble code in u-boot:

    -cpu/nios2/start.S

    -cpu/nios2/exceptions.S

    -lib_nios2/cache.S

    Regards,

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

    you are writing NiosI asm for NiosII cpu ...

    here's something:

        .file    "Main.s"
        .section    .text
        .align    3
        .global    main
        .type    main, @function
    main:
        //sp <- sp -8
        addi    sp, sp, -8
        //ra -> *(sp +4)    
        stw  ra,4(sp)      
        // fp -> *(sp)
      stw  fp,0(sp)    
      // fp -> sp
        mov  fp,sp        
    aaa:    //#define LED_BASE 0x00000820
        movhi    r13, %hiadj(0x00000820)
        addi    r13, r13, %lo(0x00000820)
        
        //valeur par bit (1) allume  (0) eteint
        movhi    r12, %hiadj(255)
        addi    r12, r12, %lo(255)
        
        //allume led
        stwio    r12, 0(r13)
        
        call    delay1
    ....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thankyou smcnutt and slvn. I will be in touch with both of you if i have any more doubts.

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

    rakesh,

    if you need more details about assembly and instruction. you should refer to reference and developper handbooks for Nios II.

    about the prog I did, it&#39;s just stupid and incomplete showing you what it looks like. (you were using Nios I assembly in your post I guess).

    If your SPOC has some leds you can replace Base Led by the address where are mapped your leds, and try something like turning the led on/off

    file "Main.s"
    .section .text
    .align 3
    .global main
    .type main, @function
    main:
        
    //#define LED_BASE 0x00000820
    movhi r13, %hiadj(0x00000820)
    addi r13, r13, %lo(0x00000820)
    //valeur par bit (1) allume  (0) eteint
    movhi r12, %hiadj(255)
    addi r12, r12, %lo(255)
    //turn led on
    stwio r12, 0(r13)
    hope it can help
    Sylvain