简体   繁体   中英

MIPS assembly, adding to jump

I'm having trouble with my assembly code:

# Program testing 
        .text
        .globl  main

main:   ori $4,$0,1
        addiu $4,$4,2
        addiu $8,$10,4
        addiu $2,$1,1
        addiu $3,$1,1
        addiu $5,$1,1
        j main+8       #ERROR HERE
        sll $0,$0,0

# End of file

I want to add to my jump. My professor says this will work but I keep getting a parser error

My MIPS setting in PCSPIM are:
checked on bare machine, delayed branches, and delayed load.

Does anyone know what is wrong? Is there a word alignment issue?

There are no word alignment issues here. Your problem is that the assembler you are using is not interpreting label+displacement as a target address.

As every instruction occupies 4 bytes, you are actually trying to jump two instructions ahead of the main label. Thus, just add a new label where you are really targeting the jump.

ie:

# Program testing 
        .text
        .globl  main

main:   ori $4,$0,1
        addiu $4,$4,2
jump_target:
        addiu $8,$10,4
        addiu $2,$1,1
        addiu $3,$1,1
        addiu $5,$1,1
        j jump_target       # main+8
        sll $0,$0,0

# End of file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM