Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

assembly - Getting the error: "Instruction references undefined symbol ... main" in QTSpim

I'm trying to compute (a * c) - (b / d), and so far my assembly code is:

.data
A: .word 5
B: .word 6
C: .word 3
D: .word 2
.text
lw $t0, A
lw $t1, C 
mul $t0, $t0, $t1 
lw $t1, B
lw $t2, D 
div $t1, $t1, $t2
sub $t0, $t0, $t1
li $v0, 1
move $a0, $t0
syscall
li $v0, 10
syscall

But when I run it, I get the error. I am new to QTSpim and assembly so I would appreciate some help if possible. Thank you!

edit:

the exact error is:

"Instruction references undefined symbol at 0x00400014 [0x00400014] 0x0c000000 jal 0x0000000 [main] ;188: jal main"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The default startup code expects your program to have a global label main as its entry point. So you need to add one, e.g.:

# (as before)
.text
.globl main
main:
# (as before)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...