Instruction references undefined error in MIPS/QTSPIM jal 0x00000000 [main] ; 188:日航主要
Instruction references undefined error in MIPS/QTSPIM jal 0x00000000 [main] ; 188: jal main
我的 code.Please 帮助中出现以下错误。
Instruction references undefined symbol at 0x00400014 [0x00400014] 0x0c000000 jal 0x00000000 [main] ; 188:日航主要
此代码将华氏度转换为摄氏度,将摄氏度转换为华氏度
.data 0x10008000
.word 5,9,32
message1:
.asciiz "Select the temparature scale:<C or F><ENTER"
message2: .asciiz "Type the desired temperature <ENTER>"
message3: asciiz "Temparature= "
.text
.globl main
main:
li $v0,4
la $a0,message1
syscall
li $v0,12
syscall
move $t0,$v0
li $t1,70
li$t2,67
beq $t0,$t1,Farenheit
beq $t0,$t2,Celcius
li $v0,10
syscall
Farenheit:
li $v0,4
la $a0,message2
syscall
li $v0,6
syscall
lui $gp, 0x1000 #I put in register $gp the number 0x10008000,which
ori $gp, $gp,0x8000 # shows in the middle of address of static data
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f16,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,$v0
sub.s $f12,$f12,$f14
mul.s $f0,$f20,$f12
la $a0,message3
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
Celcius:
li $v0,4
la $a0,message2
syscall
li $v0,6
syscall
lui $gp, 0x100
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f18,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,$v0
mul.s $f12,$f12,$f20
add.s $f0,$f12,$f14
la $a0,message3
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
您的代码甚至 assemble 都不干净。
使用 $gp
[带有硬编码偏移量] 访问 .word 5,9,32
是矫枉过正。为 .data
部分设置一个显式地址可能也不好。
"read float"系统调用return是$f0
中的值,不是$v0
摄氏度和华氏度部分之间有很多 可以合并的复制代码。
您使用的是 jr $ra
[return 来自函数],而实际上并未通过 jal
调用计算部分
应该有更多评论来解释您的逻辑流程。你可能想在这里看到我的回答: 因为它有一些关于 asm 风格和干净编码的技巧。
无论如何,这是经过清理、注释和工作的代码:
.data
temp5: .word 5
temp9: .word 9
temp32: .word 32
msg_scale: .asciiz "Select the temperature scale:<C or F><ENTER>"
msg_temp: .asciiz "Type the desired temperature <ENTER>"
msg_out: .asciiz "Temperature= "
msg_nl: .asciiz "\n"
.text
.globl main
main:
# prompt user for temp type/scale
li $v0,4
la $a0,msg_scale
syscall
# read in temp scale
li $v0,12
syscall
move $t0,$v0
# output a newline
la $a0,msg_nl
li $v0,4
syscall
# prompt for temperature
li $v0,4
la $a0,msg_temp
syscall
# read in temperature
# NOTE: result comes back in $f0 and _not_ $v0
li $v0,6
syscall
###lwc1 $f12,$v0
mov.s $f12,$f0
lwc1 $f16,temp5 # get 5
cvt.s.w $f16,$f16
lwc1 $f18,temp9 # get 9
cvt.s.w $f18,$f18
lwc1 $f14,temp32 # get 32
cvt.s.w $f14,$f14
# do fahrenheit to celcius
li $t1,'F'
beq $t0,$t1,Farenheit
li $t1,'f'
beq $t0,$t1,Farenheit
# do celcius to fahrenheit
li $t1,'C'
beq $t0,$t1,Celcius
li $t1,'c'
beq $t0,$t1,Celcius
j main_exit
# print results
main_print:
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main
main_exit:
li $v0,10
syscall
Farenheit:
div.s $f20,$f16,$f18 # get 5/9
sub.s $f12,$f12,$f14 # subtract 32 from temp
mul.s $f0,$f20,$f12 # multiply by 5/9
j main_print
Celcius:
div.s $f20,$f18,$f16 # get 9/5
mul.s $f12,$f12,$f20 # multiply by 9/5
add.s $f0,$f12,$f14 # add 32
j main_print
首先感谢您的支持,非常非常 helpful.Sorry 我的风格我是汇编的初学者,一般来说 programming.My 代码有点混乱,因为我应该完成一个不完整code.Let我的解释you.This是发音:
.data0x10008000
.word 5,9,32,100
.text
lui $gp, 0x100
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f16,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,12($gp)
cvt.s.w $f12,$f12
sub.s $f12,$f12,$f14
mul.s $f0,$f20,$f12
jr $ra
你应该完成这段代码并添加用户界面(就像我在我的代码中所做的那样),并且还应该编写一段代码,它将把 farheneit 转换为 celsius.That 这就是我感到困惑的原因:(
我的大学有同样的论文(也许你也是 Auth 的,如果不是,请不要理解这个 bracket:P)
如果您没有通过 Craigs 回复回答您的问题,请查看我的代码,它可以正常工作。
经过研究(MIPS $gp register 并通过互联网),我认为使用 gp 访问存储在静态数据段中的数据并不是一个好方法,但这就是程序被告知要完成的方式!
此外,由于没有重新初始化您的模拟器,可能会出现许多错误!
这是我的代码,希望我能帮上忙!
.data 0x10008000
.word 5, 9, 32
message1: .asciiz "Select the temparature scale:<C or F>:"
message2: .asciiz "Type the desired temperature:"
message3: .asciiz "Temparature= "
newline: .asciiz "\n"
.text
.globl main
main:
li $v0,4
la $a0,message1
syscall #prompt message
#read the character
li $v0,12
syscall
move $t0,$v0
#check the character and branch
li $t1,'F'
beq $t0,$t1,Fahrenheit
li $t1,'f'
beq $t0,$t1,Fahrenheit #fahrenheit to celsius
li $t1,'C'
beq $t0,$t1,Celsius
li $t1,'c'
beq $t0,$t1,Celsius #celsius to fahrenheit
li $v0,10
syscall #end program
Fahrenheit:
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4 #type message 2
la $a0,message2
syscall
li $v0,6
syscall #read float from user
#gp has 0x10008000
lui $gp, 0x1000
ori $gp, $gp, 0x8000 #load to f16 number 5
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16 #convert to float
lwc1 $f18, 4($gp) #load number 9 to f18
cvt.s.w $f18, $f18 #convert to float
div.s $f20, $f16, $f18 #divide 5/9 and save it to f20
lwc1 $f14, 8($gp) #load number 32
cvt.s.w $f14, $f14 #convert to float
li $v0,6 #read from user float
mov.s $f12,$f0
sub.s $f12, $f12, $f14 #Fahrenheit - 32
mul.s $f0, $f20, $f12 #(Fahrenheit-32)*5/9 ,the result
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4
la $a0,message3
syscall #type message 3
mov.s $f12,$f0
li $v0,2
syscall #type the result
jr $ra
Celsius:
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4 #type message 2
la $a0,message2
syscall
li $v0,6
syscall #read float from user
lui $gp, 0x1000
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp) #load number 5 to f16
cvt.s.w $f16, $f16 #convert to float
lwc1 $f18, 4($gp) #load number 9 to f18
cvt.s.w $f18, $f18 #convert to float
div.s $f20 , $f18,$f16 #save number 9/5( f18 / f16) to f20
lwc1 $f14, 8($gp) #load number 32 to f14
cvt.s.w $f14 $f14 #convert to float
li $v0,6 #read from user
mov.s $f12,$f0
mul.s $f0,$f12,$f20 #Celsius * 9/5
add.s $f0,$f0,$f14 #(Celsius*9/5)+32
li $v0,4
la $a0,message3
syscall #Type the Result!
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
@kintzo
嘿,Kintzo,我来自 auth。感谢您 help.I 已经完成了我的代码,它与您的代码非常相似,但是我做了两个函数,请检查我的代码并告诉我您是否需要您的意见。您还使用了 $ra (return从函数)而不通过 $jal 实际调用。Craig.Here 提到的问题是我的代码
.data 0x10008000
.word 5,9,32
msg_scale: .asciiz "Select the temperature scale:<C or F><ENTER>"
msg_temp: .asciiz "Type the desired temperature <ENTER>"
msg_out: .asciiz "Temperature= "
msg_nl: .asciiz "\n"
.text
.globl main
main:
# prompt user for temp type/scale
li $v0,4
la $a0,msg_scale
syscall
# read in temp scale
li $v0,12
syscall
move $t0,$v0
# output a newline
la $a0,msg_nl
li $v0,4
syscall
# prompt for temperature
li $v0,4
la $a0,msg_temp
syscall
# read in temperature
# NOTE: result comes back in $f0 and _not_ $v0
li $v0,6
syscall
li $t1,'F'
beq $t0,$t1,F
li $t1,'C'
beq $t0,$t1,C
F:
jal Farenheit
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main_exit
C:
jal Celcius
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main_exit
main_exit:
li $v0,10
syscall
.globl Farenheit
Farenheit:
lui $gp , 0x1000
ori $gp , $gp, 0x8000
lwc1 $f16 , 0($gp)
cvt.s.w $f16,$f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
div.s $f20,$f16,$f18 # get 5/9
mov.s $f12,$f0
sub.s $f12,$f12,$f14 # subtract 32 from given temprerature
mul.s $f0,$f20,$f12 # multiply by 5/9
jr $ra
.globl Celcius
Celcius:
lui $gp , 0x1000
ori $gp , $gp, 0x8000
lwc1 $f16 , 0($gp)
cvt.s.w $f16,$f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
div.s $f20,$f18,$f16 # get 9/5
mov.s $f12,$f0
mul.s $f12,$f12,$f20 # multiply by 9/5
add.s $f0,$f12,$f14 # add 32
jr $ra
我的 code.Please 帮助中出现以下错误。 Instruction references undefined symbol at 0x00400014 [0x00400014] 0x0c000000 jal 0x00000000 [main] ; 188:日航主要 此代码将华氏度转换为摄氏度,将摄氏度转换为华氏度
.data 0x10008000
.word 5,9,32
message1:
.asciiz "Select the temparature scale:<C or F><ENTER"
message2: .asciiz "Type the desired temperature <ENTER>"
message3: asciiz "Temparature= "
.text
.globl main
main:
li $v0,4
la $a0,message1
syscall
li $v0,12
syscall
move $t0,$v0
li $t1,70
li$t2,67
beq $t0,$t1,Farenheit
beq $t0,$t2,Celcius
li $v0,10
syscall
Farenheit:
li $v0,4
la $a0,message2
syscall
li $v0,6
syscall
lui $gp, 0x1000 #I put in register $gp the number 0x10008000,which
ori $gp, $gp,0x8000 # shows in the middle of address of static data
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f16,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,$v0
sub.s $f12,$f12,$f14
mul.s $f0,$f20,$f12
la $a0,message3
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
Celcius:
li $v0,4
la $a0,message2
syscall
li $v0,6
syscall
lui $gp, 0x100
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f18,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,$v0
mul.s $f12,$f12,$f20
add.s $f0,$f12,$f14
la $a0,message3
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
您的代码甚至 assemble 都不干净。
使用 $gp
[带有硬编码偏移量] 访问 .word 5,9,32
是矫枉过正。为 .data
部分设置一个显式地址可能也不好。
"read float"系统调用return是$f0
中的值,不是$v0
摄氏度和华氏度部分之间有很多 可以合并的复制代码。
您使用的是 jr $ra
[return 来自函数],而实际上并未通过 jal
应该有更多评论来解释您的逻辑流程。你可能想在这里看到我的回答:
无论如何,这是经过清理、注释和工作的代码:
.data
temp5: .word 5
temp9: .word 9
temp32: .word 32
msg_scale: .asciiz "Select the temperature scale:<C or F><ENTER>"
msg_temp: .asciiz "Type the desired temperature <ENTER>"
msg_out: .asciiz "Temperature= "
msg_nl: .asciiz "\n"
.text
.globl main
main:
# prompt user for temp type/scale
li $v0,4
la $a0,msg_scale
syscall
# read in temp scale
li $v0,12
syscall
move $t0,$v0
# output a newline
la $a0,msg_nl
li $v0,4
syscall
# prompt for temperature
li $v0,4
la $a0,msg_temp
syscall
# read in temperature
# NOTE: result comes back in $f0 and _not_ $v0
li $v0,6
syscall
###lwc1 $f12,$v0
mov.s $f12,$f0
lwc1 $f16,temp5 # get 5
cvt.s.w $f16,$f16
lwc1 $f18,temp9 # get 9
cvt.s.w $f18,$f18
lwc1 $f14,temp32 # get 32
cvt.s.w $f14,$f14
# do fahrenheit to celcius
li $t1,'F'
beq $t0,$t1,Farenheit
li $t1,'f'
beq $t0,$t1,Farenheit
# do celcius to fahrenheit
li $t1,'C'
beq $t0,$t1,Celcius
li $t1,'c'
beq $t0,$t1,Celcius
j main_exit
# print results
main_print:
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main
main_exit:
li $v0,10
syscall
Farenheit:
div.s $f20,$f16,$f18 # get 5/9
sub.s $f12,$f12,$f14 # subtract 32 from temp
mul.s $f0,$f20,$f12 # multiply by 5/9
j main_print
Celcius:
div.s $f20,$f18,$f16 # get 9/5
mul.s $f12,$f12,$f20 # multiply by 9/5
add.s $f0,$f12,$f14 # add 32
j main_print
首先感谢您的支持,非常非常 helpful.Sorry 我的风格我是汇编的初学者,一般来说 programming.My 代码有点混乱,因为我应该完成一个不完整code.Let我的解释you.This是发音:
.data0x10008000
.word 5,9,32,100
.text
lui $gp, 0x100
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
div.s $f20 , $f16,f
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
lwc1 $f12,12($gp)
cvt.s.w $f12,$f12
sub.s $f12,$f12,$f14
mul.s $f0,$f20,$f12
jr $ra
你应该完成这段代码并添加用户界面(就像我在我的代码中所做的那样),并且还应该编写一段代码,它将把 farheneit 转换为 celsius.That 这就是我感到困惑的原因:(
我的大学有同样的论文(也许你也是 Auth 的,如果不是,请不要理解这个 bracket:P)
如果您没有通过 Craigs 回复回答您的问题,请查看我的代码,它可以正常工作。
经过研究(MIPS $gp register 并通过互联网),我认为使用 gp 访问存储在静态数据段中的数据并不是一个好方法,但这就是程序被告知要完成的方式!
此外,由于没有重新初始化您的模拟器,可能会出现许多错误!
这是我的代码,希望我能帮上忙!
.data 0x10008000
.word 5, 9, 32
message1: .asciiz "Select the temparature scale:<C or F>:"
message2: .asciiz "Type the desired temperature:"
message3: .asciiz "Temparature= "
newline: .asciiz "\n"
.text
.globl main
main:
li $v0,4
la $a0,message1
syscall #prompt message
#read the character
li $v0,12
syscall
move $t0,$v0
#check the character and branch
li $t1,'F'
beq $t0,$t1,Fahrenheit
li $t1,'f'
beq $t0,$t1,Fahrenheit #fahrenheit to celsius
li $t1,'C'
beq $t0,$t1,Celsius
li $t1,'c'
beq $t0,$t1,Celsius #celsius to fahrenheit
li $v0,10
syscall #end program
Fahrenheit:
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4 #type message 2
la $a0,message2
syscall
li $v0,6
syscall #read float from user
#gp has 0x10008000
lui $gp, 0x1000
ori $gp, $gp, 0x8000 #load to f16 number 5
lwc1 $f16, 0($gp)
cvt.s.w $f16, $f16 #convert to float
lwc1 $f18, 4($gp) #load number 9 to f18
cvt.s.w $f18, $f18 #convert to float
div.s $f20, $f16, $f18 #divide 5/9 and save it to f20
lwc1 $f14, 8($gp) #load number 32
cvt.s.w $f14, $f14 #convert to float
li $v0,6 #read from user float
mov.s $f12,$f0
sub.s $f12, $f12, $f14 #Fahrenheit - 32
mul.s $f0, $f20, $f12 #(Fahrenheit-32)*5/9 ,the result
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4
la $a0,message3
syscall #type message 3
mov.s $f12,$f0
li $v0,2
syscall #type the result
jr $ra
Celsius:
li $v0,4
la $a0,newline
syscall #type new line
li $v0,4 #type message 2
la $a0,message2
syscall
li $v0,6
syscall #read float from user
lui $gp, 0x1000
ori $gp, $gp,0x8000
lwc1 $f16, 0($gp) #load number 5 to f16
cvt.s.w $f16, $f16 #convert to float
lwc1 $f18, 4($gp) #load number 9 to f18
cvt.s.w $f18, $f18 #convert to float
div.s $f20 , $f18,$f16 #save number 9/5( f18 / f16) to f20
lwc1 $f14, 8($gp) #load number 32 to f14
cvt.s.w $f14 $f14 #convert to float
li $v0,6 #read from user
mov.s $f12,$f0
mul.s $f0,$f12,$f20 #Celsius * 9/5
add.s $f0,$f0,$f14 #(Celsius*9/5)+32
li $v0,4
la $a0,message3
syscall #Type the Result!
mov.s $f12,$f0
li $v0,2
syscall
jr $ra
@kintzo 嘿,Kintzo,我来自 auth。感谢您 help.I 已经完成了我的代码,它与您的代码非常相似,但是我做了两个函数,请检查我的代码并告诉我您是否需要您的意见。您还使用了 $ra (return从函数)而不通过 $jal 实际调用。Craig.Here 提到的问题是我的代码
.data 0x10008000
.word 5,9,32
msg_scale: .asciiz "Select the temperature scale:<C or F><ENTER>"
msg_temp: .asciiz "Type the desired temperature <ENTER>"
msg_out: .asciiz "Temperature= "
msg_nl: .asciiz "\n"
.text
.globl main
main:
# prompt user for temp type/scale
li $v0,4
la $a0,msg_scale
syscall
# read in temp scale
li $v0,12
syscall
move $t0,$v0
# output a newline
la $a0,msg_nl
li $v0,4
syscall
# prompt for temperature
li $v0,4
la $a0,msg_temp
syscall
# read in temperature
# NOTE: result comes back in $f0 and _not_ $v0
li $v0,6
syscall
li $t1,'F'
beq $t0,$t1,F
li $t1,'C'
beq $t0,$t1,C
F:
jal Farenheit
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main_exit
C:
jal Celcius
la $a0,msg_out
li $v0,4
syscall
mov.s $f12,$f0
li $v0,2
syscall
la $a0,msg_nl
li $v0,4
syscall
j main_exit
main_exit:
li $v0,10
syscall
.globl Farenheit
Farenheit:
lui $gp , 0x1000
ori $gp , $gp, 0x8000
lwc1 $f16 , 0($gp)
cvt.s.w $f16,$f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
div.s $f20,$f16,$f18 # get 5/9
mov.s $f12,$f0
sub.s $f12,$f12,$f14 # subtract 32 from given temprerature
mul.s $f0,$f20,$f12 # multiply by 5/9
jr $ra
.globl Celcius
Celcius:
lui $gp , 0x1000
ori $gp , $gp, 0x8000
lwc1 $f16 , 0($gp)
cvt.s.w $f16,$f16
lwc1 $f18, 4($gp)
cvt.s.w $f18, $f18
lwc1 $f14, 8($gp)
cvt.s.w $f14 $f14
div.s $f20,$f18,$f16 # get 9/5
mov.s $f12,$f0
mul.s $f12,$f12,$f20 # multiply by 9/5
add.s $f0,$f12,$f14 # add 32
jr $ra